@supuwoerc/toolkit
    Preparing search index...

    Function filterTree

    • 根据匹配函数过滤树节点,并修剪不匹配的分支 Filter tree nodes by match function and prune unmatched branches

      Type Parameters

      • T = TreeNode

        节点类型 / node type

      • K extends string = "children"

        children 字段名,默认为 'children' / children key name, default 'children'

      Parameters

      • tree: Tree<T, K>[]

        树数组 / tree array

      • match: (node: T) => boolean

        匹配函数,返回 true 表示保留节点 / match function, returns true to keep node

      • OptionalchildrenKey: K = ...

        子节点字段名 / children field name

      Returns Tree<T, K>[]

      过滤后的树数组 / filtered tree array

      // 根据标题搜索
      // Search by title
      const result = filterTree(tree, (node) => node.title.includes('query'))