我无法取消选择我在 state 中设置的默认值。
到目前为止唯一的变化是添加一个对象数组而不是字符串数组。请参阅文档中提到的对象数组中的 VALUE 道具。.
const OPTIONS = [
{
label: "Expansion",
value: "1"
},
{
label: "Rollout",
value: "2"
}
];
export default class extends Component {
state = {
value: [
{
label: "Rollout",
value: "2"
}
],
options: OPTIONS
};
render() {
const { options, value } = this.state;
return (
<Select
multiple={true}
value={value}
labelKey="label"
valueKey="value"
onSearch={searchText => {
const regexp = new RegExp(searchText, "i");
this.setState({ options: OPTIONS.filter(o => o.match(regexp)) });
}}
onChange={event => {
console.log({ event });
this.setState({
value: event.value,
options: OPTIONS
});
}}
options={options}
/>
);
}
}
在日志中,selected: [ -1, 1 ]
当我尝试取消选择该Rollout
选项时,我得到了,并且Rollout
仍然在视图中突出显示/选中。