Skip to content

filterTree

Functions

filterTree()

filterTree<T>(array, iterator, options): T[]

根据迭代器过滤树列表的子项数据,仅返回符合过滤规则的节点列表

Type parameters

Parameter
T extends Object

Parameters

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

Returns

T[]

Example

ts
filterTree(
  [
    {
      id: 1,
      text: '1',
      children: [
        {
          id: 3,
          text: '3',
        }
      ]
    },
    {
      id: 2,
      text: '2',
    }
  ],
  (node) => node.id >= 2,
)
// => [{ id: 3, text: '3', }, { id: 2, text: '3', }]

Interfaces

FilterTreeOptions

Properties

PropertyTypeDescription
childrenKey?string子节点键

Default
'children'