Methods
(static) create(list, parentIdopt, idKeyopt, parentIdKeyopt, withRootopt) → {Array}
列表转换树结构
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
list |
Array.<Object> | 列表数据,约定字段名称: id/parentId/children |
||
parentId |
* |
<optional> |
null
|
父节点的值 |
idKey |
string |
<optional> |
id
|
id字段名称 |
parentIdKey |
string |
<optional> |
parentId
|
parentId字段名称 |
withRoot |
boolean |
<optional> |
false
|
有根节点id时是否保留返回根节点 |
Returns:
- Type
- Array
(static) find(data, isFindOne, fn, fieldopt) → {Array|Object}
遍历树数据节点,查找符合条件的节点
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Array | Object | 数据树,如 {id:1, children:[{id:2}]} |
||
isFindOne |
Boolean | 是否只找最先符合条件的一个 |
||
fn |
function | 查找回调函数,回调参数:item 节点,index节点当前兄弟节点中的索引,data 查找的数据树,函数返回true表示符合条件 |
||
field |
string |
<optional> |
children
|
子级字段名称 |
Returns:
查找结果,isFindOne为true时返回Object, false时返回Array
- Type
- Array | Object
(static) findPath(data, fn, fieldopt) → {Array}
查找节点在树结构数组的路径
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
Array | Object | 树数据数组, 如 {id:1, children:[{id:2}]} |
||
fn |
function | 查找回调函数,回调参数:item 节点,index节点当前兄弟节点中的索引,data 查找的数据树,函数返回true表示符合条件 |
||
field |
string |
<optional> |
children
|
子级字段名称 |
Returns:
节点路径数组
- Type
- Array
(static) treeRevert(tree, idPropopt, childrenPropopt) → {Array}
将树状数据摊平为一维数组
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
tree |
Array | 树数据数组, 如 [{id:1, children:[{id:2}]}] |
||
idProp |
string |
<optional> |
id
|
节点唯一编号字段名称 |
childrenProp |
string |
<optional> |
children
|
子级字段名称 |
Returns:
节点路径数组
- Type
- Array