diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx index 4ef9e4941..2b323669e 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/association-cascader/AssociationCascader.tsx @@ -4,12 +4,6 @@ import { connect, useFieldSchema } from '@formily/react'; import { useCollectionManager, useRequest } from '@nocobase/client'; import _ from 'lodash'; -interface Option { - name: string | number; - id: string; - children?: Option[]; -} - const AssociationCascader = connect((props) => { const fieldSchema = useFieldSchema(); const collection = fieldSchema['collectionName']; @@ -32,24 +26,20 @@ const AssociationCascader = connect((props) => { }); const options = useMemo(() => { - const dict = {}; - data?.data.forEach((item) => { - if (item[associationField]) { - dict[item[associationField][joinTitleField]] ??= []; - dict[item[associationField][joinTitleField]].push(item[titleField]); - } - }); - const options: Option[] = []; - _.forEach(dict, (values: any, key) => { - options.push({ - name: key, - id: key, - children: values.map((value) => ({ - name: value, - id: value, - })), - }); - }); + const dict: { [key: string]: string[] } = + data?.data.reduce((acc, item) => { + if (item[associationField]) { + const key = item[associationField][joinTitleField]; + acc[key] ??= []; + acc[key].push(item[titleField]); + } + return acc; + }, {}) || {}; + const options = Object.entries(dict).map(([key, values]) => ({ + name: key, + id: key, + children: values.map((value) => ({ name: value, id: value })), + })); return options; }, [associationField, joinTitleField, titleField, data?.data]); return ;