nodes是普通数组转化成递归
buildTree(nodes) {
const root = {
sid: 0,
children: [],
}
let leaves = [root]
while (leaves.length) {
let newLeaves = []
leaves.forEach((leave) => {
nodes.forEach((node) => {
if (node.parentSid === leave.sid) {
if (!leave.children) {
leave.children = [node]
} else {
leave.children.push(node)
}
newLeaves.push(node)
}
})
})
leaves = newLeaves
}
return root.children
}