我正在处理 antd select 并且在正确预填充它时遇到问题,我可以通过它的 initialValue 字段装饰器预填充选择框,但是它填充字符串,似乎没有办法获得值(我可以解决这个问题但不理想),更重要的是,如果该选项未被选中/删除,则与标准选项不同,它在选择中不再可用。我可以在选择列表选项和初始值中都包含(如下面的代码所示),但是它允许重复的自动输入,并且它在下拉列表中出现两次。任何想法我做错了什么?
预选和完整选项列表的准备
let defaultSelect = [];
let selectList = [];
for (var a = 0; a < this.props.myData.length; a++) {
//push all options to select list
selectList.push(<Select.Option key={this.props.myData[i].id} >{this.props.myData[i].name}</Select.Option>)
//this is my code to pre-populate options, by performing a find/match
let matchedTech = _.find(this.props.myDataPrepopulate, { id: this.props.myData[i].id });
if (matchedTech) {
//notice I can push just the string name, not the name and the id value.
defaultSelect.push(this.props.myData[i].name);
}
}
选择代码
{getFieldDecorator(row.name, {
initialValue: defaultSelect
})(
<Select
tags
notFoundContent='none found'
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
{selectList}
</Select>
)}