我可能只是忽略了一些东西,但我无法弄清楚为什么我似乎不能使用react-select配置多选。
这是我所看到的working example。
请注意,在多选上只能选择一项,然后在清除当前项之前不再加载下拉列表。此外,当项目被清除时,你可以看到所有的选项,看起来鼠标悬停时的高亮显示不再起作用。
代码:
import React from "react";
import { render } from "react-dom";
import Select from "react-select";
import "react-select/dist/react-select.css";
class App extends React.Component {
constructor() {
super();
this.state = {
multiValue: null,
filterOptions: [
{ name: "foo", label: "Foo" },
{ name: "bar", label: "Bar" },
{ name: "bat", label: "Bat" }
]
};
this.handleMultiChange = this.handleMultiChange.bind(this);
}
handleMultiChange(option) {
this.setState(state => {
return {
multiValue: option
};
});
console.log(option);
}
render() {
return (
<div>
<label>Multi (not working)</label>
<Select
name="filters"
placeholder="Filters"
value={this.state.multiValue}
options={this.state.filterOptions}
onChange={this.handleMultiChange}
multi
/>
</div>
);
}
}
render(<App />, document.getElementById("root"));发布于 2017-11-14 02:14:26
您为select选项设置了错误的键name而不是value
https://stackoverflow.com/questions/47270244
复制相似问题