Open fudx opened 1 year ago
function ArrayToTree(data){
let map = {},tree = []
for(let i = 0 ; i < data.length; i++) {
map[data[i].id] = data[i]
}
for(let i = 0; i < data.length; i++) {
const pid = data[i].pid
if(pid == '') {
tree = [data[i]]
} else {
!map[pid].children && (map[pid].children = [])
map[pid].children.push(data[i])
}
}
return tree
}