mapTree
Functions
mapTree()
mapTree<
T
,U
,ChildrenKey
,MappingChildrenKey
>(array
,iterator
,options
?):WithChildren
<Omit
<U
,ChildrenKey
|MappingChildrenKey
>,ChildrenKey
|MappingChildrenKey
,false
>[]
根据迭代器映射子节点生成新的树列表
Type parameters
Parameter | Value |
---|---|
T extends Object | - |
U extends Object | - |
ChildrenKey extends string | "children" |
MappingChildrenKey extends string | never |
Parameters
Parameter | Type | Description |
---|---|---|
array | T [] | 树列表 |
iterator | TreeIterator <T , U > | 迭代器 |
options ? | MapTreeOptions <ChildrenKey , MappingChildrenKey > | 配置项 |
Returns
WithChildren
<Omit
<U
, ChildrenKey
| MappingChildrenKey
>, ChildrenKey
| MappingChildrenKey
, false
>[]
Example
ts
mapTree(
[
{
id: 1,
text: '1',
children: [
{
id: 3,
text: '3',
}
]
},
{
id: 2,
text: '2',
}
],
(node) => {
if (node.id === 2) {
node.text = '22'
}
return node
},
)
// => [{...}, { id: 2, text: '22', }]
Interfaces
MapTreeOptions<ChildrenKey, MappingChildrenKey>
Type parameters
Parameter | Value |
---|---|
ChildrenKey extends string | string |
MappingChildrenKey extends string | never |
Properties
Property | Type | Description |
---|---|---|
childrenKey? | ChildrenKey | 子节点键 Default 'children' |
mapChildrenKey? | MappingChildrenKey | 映射后的子节点键,设置后则必定存在于节点上 |