diff --git a/packages/amis-core/src/utils/helper.ts b/packages/amis-core/src/utils/helper.ts index d6a79cde7..6fa0146cc 100644 --- a/packages/amis-core/src/utils/helper.ts +++ b/packages/amis-core/src/utils/helper.ts @@ -844,6 +844,27 @@ export function findTree( return result; } +/** + * 在树中查找节点。 + * @param tree + * @param iterator + */ +export function findTreeAll( + tree: Array, + iterator: (item: T, key: number, level: number, paths: Array) => any +): Array { + let result: Array = []; + + everyTree(tree, (item, key, level, paths) => { + if (iterator(item, key, level, paths)) { + result.push(item); + } + return true; + }); + + return result; +} + /** * 在树中查找节点, 返回下标数组。 * @param tree diff --git a/packages/amis-ui/src/components/formula/VariableList.tsx b/packages/amis-ui/src/components/formula/VariableList.tsx index be46669bd..df0721a4d 100644 --- a/packages/amis-ui/src/components/formula/VariableList.tsx +++ b/packages/amis-ui/src/components/formula/VariableList.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {themeable, ThemeProps, findTree} from 'amis-core'; +import {themeable, ThemeProps, findTreeAll} from 'amis-core'; import GroupedSelection from '../GroupedSelection'; import Tabs, {Tab} from '../Tabs'; import TreeSelection from '../TreeSelection'; @@ -75,8 +75,8 @@ function VariableList(props: VariableListProps) { }; function onSearch(term: string) { - const tree = findTree(list, i => ~i.label.indexOf(term)); - setFilterVars(!term ? list : tree ? [tree] : []); + const tree = findTreeAll(list, i => ~i.label.indexOf(term)); + setFilterVars(!term ? list : tree); } function renderSearchBox() {