searchTree
Functions
searchTree()
searchTree<
T
,ChildrenKey
,MappingChildrenKey
>(array
,iterator
,options
?):WithChildren
<Omit
<T
,ChildrenKey
|MappingChildrenKey
>,ChildrenKey
|MappingChildrenKey
,false
>[]
根据迭代器搜索树列表的子项数据,区别于 filterTree
会返回完整的树形结构列表
注意:当父级符合搜索规则时将保留所有子级数据!
Type parameters
Parameter | Value |
---|---|
T extends Object | - |
ChildrenKey extends string | "children" |
MappingChildrenKey extends string | never |
Parameters
Parameter | Type | Description |
---|---|---|
array | T [] | 树列表 |
iterator | TreeIterator <T , boolean > | 迭代器 |
options ? | SearchTreeOptions <ChildrenKey , MappingChildrenKey > | 配置项 |
Returns
WithChildren
<Omit
<T
, ChildrenKey
| MappingChildrenKey
>, ChildrenKey
| MappingChildrenKey
, false
>[]
Example
ts
searchTree(
[
{
id: 1,
text: '1',
children: [
{
id: 3,
text: '3',
}
]
},
{
id: 2,
text: '2',
}
],
(node) => node.id === 3,
)
// => [{ id: 1, text: '1', children: [{ id: 3, text: '3', }] }]
Interfaces
SearchTreeOptions<ChildrenKey, MappingChildrenKey>
Type parameters
Parameter | Value |
---|---|
ChildrenKey extends string | string |
MappingChildrenKey extends string | never |
Properties
Property | Type | Description |
---|---|---|
childrenKey? | ChildrenKey | 子节点键 Default 'children' |
mapChildrenKey? | MappingChildrenKey | 映射后的子节点键,设置后则必定存在于节点上 |
original? | boolean | 是否返回源对象引用,易改变源对象数据结构 Default false |
originalDataKey? | string | 源数据引用键,original 为 false 时生效,未设置时则不引用源数据 |