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
  }
posted on 2020-12-31 17:06  祁祁  阅读(185)  评论(0编辑  收藏  举报