Yansen 2 年之前
父節點
當前提交
7b8af96149
共有 1 個檔案被更改,包括 3 行新增2 行删除
  1. 3
    2
      src/utils/array.js

+ 3
- 2
src/utils/array.js 查看文件

@@ -21,14 +21,15 @@ export function arr2Tree(arr = [], parent = 'parentId', key = 'key', rootId = '-
21 21
   // 挂载父子节点
22 22
   const tree = [];
23 23
   for (let item of arr) {
24
+    const node = dict[item[key]];
24 25
     const parentNodeId = item[parent];
25 26
 
26 27
     if (parentNodeId === rootId) {
27
-      tree.push(dict[item[key]]);
28
+      tree.push(node);
28 29
     } else {
29 30
       const parentNode = dict[parentNodeId];
30 31
       if (parentNode) {
31
-        parentNode.children.push(item);
32
+        parentNode.children.push(node);
32 33
       }
33 34
     }
34 35
   }