关于根据动态数量的对象的某属性的数组数量呈乘机式增长的数据处理

adta是原始数组,currentIndex默认是零,currentObject初始对象,result处理生成的结果

javascript 复制代码
function generateObjects(data, currentIndex, currentObject, result) {
    if (currentIndex === data.length) {
      result.push(currentObject);
      return;
    }

    const currentCode = data[currentIndex].code;
    const currentSelect = data[currentIndex].select;

    for (let i = 0; i < currentSelect.length; i++) {
      const newObject = { ...currentObject };
      newObject[currentCode] = currentSelect[i];
      generateObjects(data, currentIndex + 1, newObject, result);
    }
  }

  const result = [];
  generateObjects(data, 0, {}, result);
相关推荐
笋笋~18 分钟前
el-tree 拖拽事件隔离:实现句柄独立控制,区域分离
javascript·vue.js·elementui
Aotman_2 小时前
Element UI 表格搜索高亮
前端·javascript·vue.js·ui·elementui
Dillon Dong2 小时前
【系列主题】拯救 OOM 与构建中断:Next.js 在 Docker 中的静态生成(SSG)避坑指南
开发语言·javascript·docker
han_hanker2 小时前
下拉模糊搜索多选, 编辑,详情问题
开发语言·javascript·ecmascript
yqcoder3 小时前
[特殊字符] Vue 3 中 Keep-Alive 对生命周期的影响:深度解析
前端·javascript·vue.js
jiayong233 小时前
第 33 课:任务看板视图(按状态分列)与本地持久化
开发语言·前端·javascript·学习
Yeats_Liao3 小时前
后台 Sidebar 伸缩交互(PC + 移动端)实现
前端·javascript·css·html5
MXN_小南学前端3 小时前
computed 计算属性详解:触发时机、实战场景、Vue2 与 Vue3 对比
前端·javascript·vue.js
isNotNullX4 小时前
数据大屏怎么做?数据大屏有哪四个核心环节
开发语言·前端·javascript
竹林8184 小时前
Web3表单签名验证:我如何用 wagmi 和 siwe 让用户“无密码”登录
javascript