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>
)}
您發佈的代碼中有許多語法錯誤:我未定義,<選擇標籤未關閉等。 –