页面点击编辑按钮,根据后台传过来的keys动态增加表单项,但是无法通过setFieldsValue方式设置初始值,请问应该如何做?
{keys.map((k, index) => {
console.log(k);
console.log(`index: ${index}`);
return (
<div className="formSelect relatePaper">
<FormItem>
{getFieldDecorator(`paperId-${k}`, {
initialValue: ''
})(
<Select showSearch style={{width: 200}}
placeholder="请输入试卷名称"
optionFilterProp="children"
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
>
<Option value="">--请选择--</Option>
{
!this.props.examPapers ? "" : this.props.examPapers.map(examPaper =>
<Option key={examPaper.id}
value={examPaper.id}>{examPaper.paperName}</Option>)
}
</Select>
)}
</FormItem>
<FormItem >
{getFieldDecorator(`paperDuration-${k}`, {
initialValue: ''
})(
<Select style={{width: 70}}>
<Option value={-1}>不限</Option>
<Option value={5}>5分钟</Option>
</Select>
)}
</FormItem>
<FormItem label="分数线">
{getFieldDecorator(`scoreLine-${k}`, {})(<InputNumber style={{width: 50}}
min={0}/>)}
</FormItem>
<div className="addIcon">
<Button type="ghost" shape="circle" icon="minus"
onClick={() => this.remove(k)}/>
</div>
</div>
);
})
}
我是通过 设置动态的属性名方式实现的
[ "prop_" + (() => 42)() ]
输出: