Преглед изворни кода

feat: 支持传入空数组

zhangweicheng пре 5 година
родитељ
комит
77028bda5f
1 измењених фајлова са 1 додато и 1 уклоњено
  1. 1 1
      tree/src/index.ts

+ 1 - 1
tree/src/index.ts

@@ -96,7 +96,7 @@ export class Tree {
 
 
   // 获取顶层原始数据
   // 获取顶层原始数据
   getRoots(): TreeNode[] {
   getRoots(): TreeNode[] {
-    return this.parentMap[this.rootID];
+    return this.parentMap[this.rootID] || [];
   }
   }
 
 
   // 生成按照树结构排好序的数据
   // 生成按照树结构排好序的数据