我们写代码,肯定有遇到过getFieldDecorator绑定的 `exactMatch-${record.id}` 这样的控件变量名
{getFieldDecorator(`exactMatch-${record.id}`, {
})(
<InputNumber min={0} style={{ width: 80 }}/>
)}
赋值的时候,this.props.form.setFieldsValue({ `exactMatch-${record.id}` : 123,})这样写代码会报错,应为属性分配;
let wqfhlName = `exactMatch-${record.id}`; this.props.form.setFieldsValue({wqfhlName: 123,}),//这样写,不会将wqfhlName与`exactMatch-${record.id}`对应,浏览器会报You cannot set a form field before rendering a field associated with the value。
这时,我们可以这样写,解决了。
this.props.form.setFieldsValue({
[`exactMatchRatio-${record.id}`]: 123,
})