Skip to content

findTree

Functions

findTree()

findTree<T>(array, iterator, options?): undefined | FindResult<T>

根据迭代器查找树列表子节点

Type parameters

Parameter
T extends Object

Parameters

ParameterTypeDescription
arrayT[]树列表
iteratorTreeIterator<T, boolean>迭代器
options?FindTreeOptions配置项

Returns

undefined | FindResult<T>

Example

ts
findTree(
  [
    {
      id: 1,
      text: '1',
      children: [
        {
          id: 3,
          text: '3',
        }
      ]
    },
    {
      id: 2,
      text: '2',
    }
  ],
  (node) => node.id >= 2,
)
// => { index: 0, node: { id: 3, text: '3', }, paths: ['0', 'children', '0'], nodes: [{ id: 1, text: '1', children: [{...}], }, { id: 3, text: '3', }], tree: [...] }

Interfaces

FindResult<T>

Type parameters

Parameter
T

Properties

PropertyTypeDescription
indexnumber-
nodeT-
nodesT[]-
parent?T-
pathsstring[]-
treeT[]-

FindTreeOptions

Properties

PropertyTypeDescription
childrenKey?string子节点键

Default
'children'