|
|
@@ -0,0 +1,50 @@
|
|
|
+# Tree
|
|
|
+
|
|
|
+基于 TypeScript 编写的树结构库
|
|
|
+
|
|
|
+### 安装
|
|
|
+
|
|
|
+`$ npm i -S @sc/tree`
|
|
|
+
|
|
|
+### 测试
|
|
|
+
|
|
|
+`$ npm run test`
|
|
|
+
|
|
|
+### 基本用法
|
|
|
+
|
|
|
+```
|
|
|
+const rawData: TreeRaw[] = [
|
|
|
+ { ID: '1', parentID: '-1', seq: 1 },
|
|
|
+ { ID: '2', parentID: '-1', seq: 2 },
|
|
|
+ { ID: '3', parentID: '-1', seq: 3 },
|
|
|
+];
|
|
|
+
|
|
|
+const tree = new Tree(rawData);
|
|
|
+```
|
|
|
+
|
|
|
+### 树方法
|
|
|
+
|
|
|
+```
|
|
|
+const node = tree.find('1');
|
|
|
+
|
|
|
+tree.prepareInsert(rawData);
|
|
|
+
|
|
|
+...
|
|
|
+```
|
|
|
+
|
|
|
+### 节点方法
|
|
|
+
|
|
|
+节点可用的方法均挂载在节点的**ctx**对象中。
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+node.ctx.row();
|
|
|
+
|
|
|
+node.ctx.parent();
|
|
|
+
|
|
|
+node.ctx.children();
|
|
|
+
|
|
|
+...
|
|
|
+```
|
|
|
+
|
|
|
+具体接口请参考声明文件。
|