Forráskód Böngészése

feat(tree): new Tree可以传入rootID

vian 5 éve
szülő
commit
a075372562
2 módosított fájl, 4 hozzáadás és 3 törlés
  1. 1 1
      tree/package.json
  2. 3 2
      tree/src/tree.ts

+ 1 - 1
tree/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@sc/tree",
-  "version": "1.0.9",
+  "version": "1.0.10",
   "description": "a template for npm package coding",
   "main": "./dist/index.cjs.js",
   "module": "./dist/index.esm.js",

+ 3 - 2
tree/src/tree.ts

@@ -47,7 +47,7 @@ export class Tree {
   // 按照树结构拼装好、排好序的数据。实际只是原始数据进行排序,内部元素跟原始数据内部元素的引用是一致的
   data: TreeNode[];
 
-  readonly rootID: string = '-1';
+  rootID: string;
 
   // 默认初始顺序号。在对树结构进行操作后,没必要保证seq连号,只需保证正确排序就行,以减少需要更新的节点。
   readonly seqStartIndex = 0;
@@ -61,7 +61,8 @@ export class Tree {
   // 节点上下文与节点ID映射
   ctxMap: CtxIDMap;
 
-  constructor(rawData: TreeRaw[]) {
+  constructor(rawData: TreeRaw[], rootID = '-1') {
+    this.rootID = rootID;
     this.rawData = this.genNodeContext(rawData);
     this.rawData = Tree.sort(this.rawData);
     this.data = [];