import React PureComponent from react;import connect from dva;import Form Input Modal Select Row Col from antd;const Option = Select;const FormItem = FormItem;Formcreateconnect filterBlock =
问题描述:点击编辑新增数据,然后再点击确定之后再打开编辑,新增的数据就没了。
问题原因:在handleSave函数中,获取表单字段的值时,使用了fieldsValue.content,但是实际上表单字段的名称是list,所以获取到的值为空数组,导致新增的数据没有保存。
解决方法:将fieldsValue.content改为fieldsValue.list即可。
修改后的代码如下:
handleSave = () => {
const { form, okChange, index, record, filterList } = this.props;
const { formVals: oldValue, keyId } = this.state;
form.validateFields((err, fieldsValue) => {
if (err) return;
const arrData = fieldsValue.list.reduce((arr, next) => {
const typeList = next.type.map(type => {
return { type, name: next.name };
});
return arr.concat(typeList);
}, []);
const nameValue = (filterList || []).find(item => item.id === keyId)?.title;
const valueId = (filterList || []).find(item => item.title === fieldsValue.value)?.id;
const formItem = {
key: keyId || valueId,
value: nameValue || fieldsValue.value,
typeList: arrData,
};
console.log(formItem, 80);
okChange(formItem, index);
this.handleVisible();
});
};
这样就能正确保存新增的数据了
原文地址: https://www.cveoy.top/t/topic/iD5i 著作权归作者所有。请勿转载和采集!