對象數組,擁有id, pid,父子結構,希望通過一個id值,來獲取其所有子節點;
注意: array一定要是全局的變量;這樣就能獲取其下的所有子節點了;
let array = []
getChildren = (list, id)=> {
? ? ? ? list.forEach(it => {
? ? ? ? ? ? ? ? if (it.pid == id) {
? ? ? ? ? ? ? ? ? ? ? ? array.push(it)
? ? ? ? ? ? ? ? ? ? ? ? getChildren(list, it.id)
????????????????}
????????} )
}