refactor: m2m data filtering through collection data (#2497)

This commit is contained in:
katherinehhh 2023-08-21 22:08:37 +08:00 committed by GitHub
parent ccf8b651ff
commit 0532d67e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,7 +89,10 @@ export const FormItem: any = observer(
let iniValues = []; let iniValues = [];
contextData?.map((v) => { contextData?.map((v) => {
const data = parseVariables(schema.default, { $context: v }); const data = parseVariables(schema.default, { $context: v });
iniValues = iniValues.concat(data); iniValues = iniValues.concat(data).map((v) => {
delete v[collectionField.through];
return v;
});
}); });
const data = _.uniqBy(iniValues, 'id'); const data = _.uniqBy(iniValues, 'id');
field.setInitialValue?.(data.length > 0 ? data : [{}]); field.setInitialValue?.(data.length > 0 ? data : [{}]);