我正在尝试使用React中的onChange事件动态调用两个函数以实现搜索功能。在第一个函数中,我正在设置值的状态,而在第二个函数中,我必须调用该值并执行函数。但我无法同时调用这两个函数。本示例代码没有添加模拟JSON数据。
handleChange(e) {
this.setState({ value: e.target.value.substr(0, 20) });
}
filterFunction(filteredSections) {
let search = filteredSections;
search = filteredSections.filter(somesection => somesection.insidesection && somesection.insidesection.name.toLowerCase().indexOf(this.state.value.toLowerCase()) !== -1);
return search;
}
render() {
const filteredSections = othersection;
return(
<div>
<FormControl
name="searching"
placeholder="Searching"
onChange={e => this.handleChange(e).bind(this)}
onChange={() => this.filterFunction(filteredSections)}
/>
</div>
<div>
{filteredSections.map(section =><othersection customization={section} } }
</div>
)
}
预期的是 onchange 事件必须调用两个函数。
value
传递给第二个函数。 - Herohtar