数据格式:
let arr = [{
'id': '0001',
'children':[
{'id':'0001001','children':[
{'id':'0001001001','children':[]},
{'id':'0001001002','children':[]}
]},
{'id':'0001002','children':[]},
{'id':'0001003','children':[]}
]
}]
递归方法调用:
function text(arr){
arr.forEach(item => {
item.disabled = true;
if(item.children.length > 0) text(item.children)
})
return arr;//返回最终结果
}
console.log(text(arr))
匿名函数调用递归:
let newArr = function(arr){
arr.forEach(item => {
item.disabled = true;
if(item.children.length > 0) text(item.children)
})
return arr;//返回最终结果
}
console.log(newArr(arr))