蓝胖子敲代码 2022-05-19 21:47 采纳率: 78.8%
浏览 35
已结题

数据处理,递归直到末端,如果children: null,就在上一个children的同级加一个 disable: true

没处理之前的数据
listTerms: [
{
id: '11',
path: 1.1,
name: '81',
children: [
{
id: '22',
path: 1.1,
name: '82',
children: [
{
id: '55',
path: '1.1.1',
name: '83',
children: null
},
{
id: '66',
path: '1.1.2',
name: '84',
children: null
}
]
},

    }
  ],

处理之后的数据

listTerms: [
{
id: '11',
path: 1.1,
name: '81',
children: [
{
id: '22',
path: 1.1,
name: '82',
disable: true,
children: [
{
id: '55',
path: '1.1.1',
name: '83',
children: null
},
{
id: '66',
path: '1.1.2',
name: '84',
children: null
}
]
},

    }
  ],
  • 写回答

1条回答 默认 最新

  • Li59297 2022-08-01 17:59
    关注
    const deepFn = (list, str) => {
        list.forEach(item=>{
          const findStrObj = item[str].find(sonItem=>Object.prototype.toString.call(sonItem[str]) === '[object Null]');
          if(findStrObj){
            item.display = true;
          }else{
            deepFn(item[str], str)
          }
        })
        return list;
      }
      console.log(deepFn(listTerms, 'children'))
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月4日
  • 已采纳回答 10月27日
  • 创建了问题 5月19日

悬赏问题

  • ¥20 jupyter保存图像功能的实现
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
  • ¥15 NAO机器人的录音程序保存问题
  • ¥15 C#读写EXCEL文件,不同编译
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理