1.0.5 • Published 2 years ago

luo-ergodic-tree v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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.

1.0.5

2 years ago

1.0.4

3 years ago

1.0.3

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago