0
我正在研究antd选择和正确预填充问题,我可以通过它的initialValue字段装饰器预填充选择框,但它填充字符串,似乎没有办法有一个值(我可以解决但不理想),更重要的是,如果该选项未被选中/删除,它将不再在选择中可用,与标准选项不同。我可以包含选择列表选项和初始值(如下面的代码所示),但它允许重复自动输入,并在下拉列表中出现两次。任何想法我做错了什么?预选的antd prepopulate标签和多选
水面浮油和全部选项列表
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>
)}
您发布的代码中有许多语法错误:我未定义,<选择标签未关闭等。 –