dlsjs 0.1.25 → 0.1.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "林川",
4
4
  "license": "MIT",
5
5
  "private": false,
6
- "version": "0.1.25",
6
+ "version": "0.1.26",
7
7
  "description": "domain-language for js",
8
8
  "main": "dist/dlsjs.esm.js",
9
9
  "module": "dist/dlsjs.esm.js",
@@ -23,13 +23,20 @@ export function list2Tree (list, extendProps = {}) {
23
23
  };
24
24
 
25
25
  // 校验数据结构
26
- if(list[0] && !list[0].hasOwnProperty('id')) {
26
+ if(list[0] && !list[0].hasOwnProperty(props.id)) {
27
27
  console.warn('数据非标准,未找到唯一标识字段,直接返回')
28
28
  return list
29
29
  }
30
30
 
31
31
  const { id: idKey, children: childrenKey, parentId: parentIdKey, useConcat } = props;
32
32
 
33
+ // -1.先清空children。防止重复叠加调用。
34
+ if(useConcat === false) {
35
+ for (const node of list) {
36
+ delete node[childrenKey];
37
+ }
38
+ }
39
+
33
40
  // 2. 构建ID到节点的哈希映射(O(n)),同时初始化children数组
34
41
  const nodeMap = new Map();
35
42
  const rootNodes = []; // 存储根节点(parentId为空/0/不存在的节点)