// ****** 对象数组 ==> 树__arrToTree(arr, pid = "superiorId", id = "id") { let tree = []; _.remove(arr, item => { if (item[pid] === "0"){ tree.push(item) return true } return false }) // 递归 const getChildren = (arr, tree, pid, id) => { if (!arr || !tree)return; tree.forEach(i => { _.remove(arr, j => { if (j[pid] === i[id]) { i.children.push(j) return true } return false }) if (i.children.length === 0) { delete i.children; }else { getChildren(arr, i.children, pid, id) } }) } getChildren(arr, tree, pid, id) return tree}// ******