luo-ergodic-tree
v1.0.5
Published
Ergodic tree
Downloads
3
Readme
Luo-Ergodic-Tree
Ergodic tree
Install
npm install luo-ergodic-tree -S
Usage
示例1
import luoErgodicTree from 'luo-ergodic-tree';
let data = [
{
key: '0',
children: [
{
key: '1',
children: []
}
]
}
];
let arr = luoErgodicTree(data, 'sn', (item, parent, index, pid) => {
item.id = 'xxz';
item.name = 'zzz';
});
console.log(arr);
示例2
import luoErgodicTree from 'luo-ergodic-tree';
let data = [
{
key: '0',
children: [
{
key: '1',
children: []
}
]
}
];
let arr = luoErgodicTree(data, 'sn', (item, parent, index, pid) => {
item.id = 'xxz';
item.name = 'zzz';
}, true);
console.log(arr);
示例3
import luoErgodicTree from 'luo-ergodic-tree';
let data = [
{
key: '0',
children: [
{
key: '1',
children: []
}
]
}
];
let arr = luoErgodicTree(data, 'sn', (item, parent, index, pid) => {
item.id = 'xxz';
item.name = 'zzz';
if (!item.id) return undefined;
return item;
}, true);
console.log(arr);
Props
| 参数类型 | 说明 | | ---------- | ----------- | | Array | 要解析的树型数组 | | String | 树的children名 | | Function | 解析第一层时的回调 | | Boolean | 是否在解析前把原始数据格式化(可选) | | mode | 模式(可选)1为必需在回调函数里返回值,2为必需在回调函数里返回值并过滤undefined |
回调返回参数说明 | 名称 | 说明 | | ---------- | ----------- | | item | 当前节点 | | parent | 父节点 | | index | 当前索引 | | pid | 层次id |
License
This content is released under the MIT License.