使用Select组件,发现默认的值是ID,而不是名称,
第一种可能是这个ID在列表中不存在,它没有对应的名称,因此只显示ID
第二种可能是向我这样data.studentId的类型为string,而value中的类型为int,两个类型不同导致显示不了,直接把data.studentId进行转换成int就可以了。
找了半天的问题,最后还是同事帮忙看出来的,一定要仔细一点!!
<Form.Item>
{form.getFieldDecorator("studentId",{
rules:[{required:true,message:'学生不能为空!'}],
initialValue:data.studentId
})(
<Select>
{studentList.map(item=>(
<Select.Option key={item.studentId} value={item.studentId}>{item.studentName}</Select.Option>
))}
</Select>
)}
</Form.Item>