leta=[{key:1,title:'一级',parentKey:0,status:{choose:false},children:[{key:10,title:'一级-0',parentKey:1,status:{choose:false},children:[{key:15,title:'一级-0-1',parentKey:10,status:{choose:false}}]},{key:11,title:'一级-1',parentKey:1,status:{choose:false}},{key:12,title:'一级-2',parentKey:1,status:{choose:false}},{key:13,title:'一级-3',parentKey:1,status:{choose:false}},{key:14,title:'一级-4',parentKey:1,status:{choose:false}}]}];letparent=(data,obj)=>{data.forEach(item=>{if(item.key===obj.parentKey){//改为trueitem.status.choose=true;parent(data,item);}if(item.children&&item.children.length){parent(item.children,obj);}});};letobj={key:15,title:'一级-0-1',parentKey:10,status:{choose:false}};parent(a,obj);console.log(a);可是执行结果下来就只有key10修改到了循环上去理应key1的choose为true啊目前只有key修改到了!看了好半会。没理解到为啥不执行上去!
MMTTMM
慕沐林林
相关分类