根据匹配函数过滤树节点,并修剪不匹配的分支 Filter tree nodes by match function and prune unmatched branches
节点类型 / node type
children 字段名,默认为 'children' / children key name, default 'children'
树数组 / tree array
匹配函数,返回 true 表示保留节点 / match function, returns true to keep node
Optional
子节点字段名 / children field name
过滤后的树数组 / filtered tree array
// 根据标题搜索// Search by titleconst result = filterTree(tree, (node) => node.title.includes('query')) Copy
// 根据标题搜索// Search by titleconst result = filterTree(tree, (node) => node.title.includes('query'))
根据匹配函数过滤树节点,并修剪不匹配的分支 Filter tree nodes by match function and prune unmatched branches