对象数组,拥有id, pid,父子结构,希望通过一个id值,来获取其所有子节点;
注意: array一定要是全局的变量;这样就能获取其下的所有子节点了;
let array = []
getChildren = (list, id)=> {
list.forEach(it => {
if (it.pid == id) {
array.push(it)
getChildren(list, it.id)
}
} )
}
对象数组,拥有id, pid,父子结构,希望通过一个id值,来获取其所有子节点;
注意: array一定要是全局的变量;这样就能获取其下的所有子节点了;
let array = []
getChildren = (list, id)=> {
list.forEach(it => {
if (it.pid == id) {
array.push(it)
getChildren(list, it.id)
}
} )
}