Skip to content

Commit

Permalink
feat: 支持 formList 初始化渲染initialData 数据 (#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
honkinglin authored Jul 8, 2022
1 parent f60f693 commit dd1ebe8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/_common
10 changes: 9 additions & 1 deletion src/form/FormList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ const FormList = (props: TdFormListProps) => {
const { name, initialData = [], rules, children } = props;

const [initialValue, setInitialValue] = useState(initialData);
const [fields, setFields] = useState<Array<FormListField>>([]);
const [fields, setFields] = useState<Array<FormListField>>(
initialData.map((data, index) => ({
key: (key += 1),
name: index,
isListField: true,
...data,
})),
);
const formListMapRef = useRef(new Map()); // 收集 formItem 实例
const formListRef = useRef<FormItemInstance>(); // 当前 formList 实例

Expand Down Expand Up @@ -40,6 +47,7 @@ const FormList = (props: TdFormListProps) => {
})
.map((field, index) => Object.assign(field, { name: index }));

setInitialValue(initialValue.filter((_, idx) => idx !== index));
setFields(nextFields);
},
move(from: number, to: number) {
Expand Down

0 comments on commit dd1ebe8

Please sign in to comment.