猿问

javascript深度遍历二叉树问题

我就直接上代码吧!直接在浏览器跑下就知道了!各位大神就是报了个错
functionobjectIterator(object,arr,objStack){
letcount=0
if(!arr.length){
return
}
if(arr.indexOf(object.id)>-1){
object.disabled=true
}
if(object.children.length){
objStack.push(object)
}else{
return
}
console.warn(objStack.length,objStack[0])
while(objStack.length){
for(leti=count;ithis.objectIterator(objStack[objStack.length-1].children[i],arr,objStack)
}
letobj=objStack.pop()
if(obj.parent&&obj.parent.children&&Array.isArray(obj.parent.children)){
count=obj.parent.children.indexOf(obj)+1
}else{
count=0
}
}
}
letobj={
id:'1',
name:'1name',
disabled:false,
parent:null,
children:[{
id:'2',
name:'2name',
disabled:false,
children:[{
id:'5',
name:'5name',
disabled:false,
children:[]
}]
},{
id:'3',
name:'3name',
disabled:false,
children:[]
},{
id:'4',
name:'4name',
disabled:false,
children:[]
}]
}
obj.children.forEach(item=>{
item.parent=obj
})
obj.children[0].children.forEach(item=>{
item.parent=obj.children[0]
})
objectIterator(obj,['1','2','5'],[])
console.warn(obj)
慕勒3428872
浏览 568回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答