我正在学习做出反应并尝试根据所选元素更新反应状态。我正在使用反应选择。它现在显示所有数据。但是当我从选择框中选择选项时,我想更新数据。如果我选择多个选项,那么它应该更新过滤所选选项的状态。
const reviews = [
{
"id": 1,
"rating": 5,
"label": [
"Sports",
"Sleep"
],
},
{
"id": 3,
"rating": 5,
"label": [
"Sports",
"Pain"
],
},
];
class SelectCreateFilter extends React.Component {
state = {
multi: null,
data: reviews,
health: healthBenefitsOptions,
category: productCategoryOptions,
products: productOptions,
};
handleChange = name => value => {
this.setState({
[name]: value,
data: this.state.data.filter() //how to perform the data mathcing to reviews.label
});
};
render() {
return (
<div>
<Select
options={groupedOptions}
components={components}
value={multi}
onChange={this.handleChange('multi')}
placeholder="Select multiple tags or products for reviews"
isMulti
isSearchable
/>
</div>
);
}
}
提前感谢您的帮助。这是来自codesandbox的代码,以便您可以检查上面的代码 https://codesandbox.io/embed/jlro0vo4n3?fontsize=14