README.md 960 B

Tree

基于 TypeScript 编写的树结构库

安装

$ npm i -S @sc/tree

测试

$ npm run test

打包

$ npm run build

基本用法

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循环引用导致handsontable栈溢出,因此节点方法及属性不再直接挂载到ctx对象中,而是通过getCtx()获取节点上下文对象


node.getCtx().row();

node.getCtx().parent();

node.getCtx().children();

...

具体接口请参考声明文件。

开发注意事项

  1. 为了响应式节点(proxy对象)可正常进行操作,代码中关于节点是否相同的判断,需要判断节点ID相同,而不是节点引用是否相同。