问:初始值中有一个初始值,但不显示该初始值。请回答这个问题
const formItem = [
{type: 3, label: 'cabinet number', name: 'ID', width: '150px', required: true},
{type: 1, label: 'cabinet name', name: 'name', width: '150px',},
{type: 1, label: 'warehouse', name: 'warehouse', width: '150px'},
{type: 1, label: 'capacity', name: 'capacity', width: '150px'},
{type: 1, label: 'operator', name: 'people', width: '150px',},
{type: 3, label: 'contact', name: 'phoneNum', width: '300px'},
{type: 1, label: 'cabinet address', name:' address', width: '300px'},
{type: 2, label: 'cabinet status', name:' status', width: '150px', value: ['disabled ',' normal ']},
{type: 1, label: 'operator', name: 'operator', width: '150px'},
];
{formItem.map(i => (
<Col key={i.name} span={i.span ? i.span : 12}>
<Form.Item {...formItemLayout} label={i.label} help={i.help}>
{getFieldDecorator(i.name, {
initialValue: initial ? initial[i.name] : null,
rules: [{ required: i.name === 'ID' ? true : false }]
})((() => {
console.log(initial)
switch (i.type) {
case 1:
return <div>
<Input style={{ width: `${i.width}` }} />
</div>
case 2:
return <Select style={{ width: `${i.width}` }}>
{i.value.map(v => (<Option key={v} value={v}>{v}</Option>))}
</Select>
case 3:
return <div>
<Input style={{ width: `${i.width}` }} />
</div>
default:
return null
}
})())}
</Form.Item>
</Col>
))}
每个项目的初始值都设置在箭头所指的位置,但是表单无法获取它。请确保在初始值中有一个初始值,但不会显示该表格。请回答!
答:如果getFieldDecorator单独Input写initialValue没有问题,但是它能工作在span套餐一,需要给予Input加分defaultValue从经验上,我不
知道为什么
答:initial ? initial[i.name] : null
这样写它initial不应该是布尔值,而是一个对象