【发布时间】:2020-05-27 22:51:19
【问题描述】:
如何在 react-select 中通过 id 设置值 比如我想根据ID的值来选择标签值。 id = "2" 结果 = "夏天"
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = { selectedOption: "" };
}
options = [
{ id: "1", value: "Spring", label: "Spring" },
{ id: "2", value: "Summer", label: "Summer" },
{ id: "3", value: "Autumn", label: "Autumn" },
{ id: "4", value: "Winter", label: "Winter" }
];
handleChange = selectedOption => {
this.setState({ selectedOption });
};
render() {
return (
<Select
value={this.state.selectedOption}
onChange={this.handleChange}
options={this.options}
/>
);
}
}
在这里你可以看到我的CodeSandbox。 提前感谢您的帮助和指导
【问题讨论】:
标签: reactjs react-select