vian d18947eec5 fix(tree): prepareSpecialMove问题 %!s(int64=3) %!d(string=hai) anos
..
src d18947eec5 fix(tree): prepareSpecialMove问题 %!s(int64=3) %!d(string=hai) anos
tests 43949d633b feat(tree): 节点序号错乱的情况下支持正常上下移 %!s(int64=3) %!d(string=hai) anos
.eslintignore 59a7f87d7a feat: tree initial commit %!s(int64=5) %!d(string=hai) anos
.eslintrc.js 998e3d8e81 feat(tree): 1.0.1 %!s(int64=5) %!d(string=hai) anos
.gitignore ebde4a48a4 chore: npm publish指定特定文件 %!s(int64=5) %!d(string=hai) anos
.huskyrc.js 59a7f87d7a feat: tree initial commit %!s(int64=5) %!d(string=hai) anos
README.md 4f5fb66c96 feat(tree): 适应响应式节点数据(proxy对象等) %!s(int64=4) %!d(string=hai) anos
commitlint.config.js 59a7f87d7a feat: tree initial commit %!s(int64=5) %!d(string=hai) anos
lint-staged.config.js 59a7f87d7a feat: tree initial commit %!s(int64=5) %!d(string=hai) anos
package-lock.json 4f5fb66c96 feat(tree): 适应响应式节点数据(proxy对象等) %!s(int64=4) %!d(string=hai) anos
package.json 43949d633b feat(tree): 节点序号错乱的情况下支持正常上下移 %!s(int64=3) %!d(string=hai) anos
prettier.config.js 59a7f87d7a feat: tree initial commit %!s(int64=5) %!d(string=hai) anos
rollup.config.js cdd5baad59 chore: 打包时,增加输出esm %!s(int64=4) %!d(string=hai) anos
tsconfig.json 59a7f87d7a feat: tree initial commit %!s(int64=5) %!d(string=hai) anos

README.md

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相同,而不是节点引用是否相同。