This example的react-tables使用react-select作为自定义过滤器,但是将react-select的版本从v1.2.1升级到v2.1.1后,我收到错误entry.map is not a function
从下拉列表中选择一个选项。
选择组件如下,有人知道为什么 .map 不再起作用吗?
<Select
style={{ width: "50%", marginBottom: "20px" }}
onChange={entry => {
console.log(entry);
this.setState({ select2: entry });
this.onFilteredChangeCustom(
entry.map(o => {
return o.value
}),
"firstName"
);
}}
value={this.state.select2}
multi={true}
options={this.state.data.map((o, i) => {
return { id: i, value: o.firstName, label: o.firstName };
})}
/>
最佳答案
Entry 是一个对象,而不是数组,因此不能在其上使用 map。使用条目的 value 属性似乎可行。
<Select
style={{ width: "50%", marginBottom: "20px" }}
onChange={entry => {
this.setState({ select2: entry });
this.onFilteredChangeCustom(
entry.value,
"firstName"
);
}}
value={this.state.select2}
multi={true}
options={this.state.data.map((o, i) => {
return { id: i, value: o.firstName, label: o.firstName };
})}
/>
关于reactjs - react 选择:选择选项后无法映射值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53243743/