Explorar o código

feat(tree): add clear()

vian %!s(int64=5) %!d(string=hai) anos
pai
achega
e1d5c73074
Modificáronse 2 ficheiros con 10 adicións e 1 borrados
  1. 1 1
      tree/package.json
  2. 9 0
      tree/src/tree.ts

+ 1 - 1
tree/package.json

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

+ 9 - 0
tree/src/tree.ts

@@ -593,4 +593,13 @@ export class Tree {
     this.updateValue(updateData);
     this.resortDataByID([orgParentID, newParentID]);
   }
+
+  // 清除所有节点(不变更data引用)
+  clear(): void {
+    this.rawData.splice(0, this.rawData.length);
+    this.data.splice(0, this.data.length);
+    this.parentMap = {};
+    this.IDMap = {};
+    this.ctxMap = {};
+  }
 }