从另一个输入填充输入

Populate input from another input

我有一个搜索功能,在点击时,我希望它解析从我创建的搜索栏收到的任何输入,以分别对 table 的搜索栏做出反应。

https://codesandbox.io/s/mystifying-microservice-ywyt2

您可以使用 Array.filter 方法针对各种条件和优先级手动过滤数据。

基本实现可以参考this沙盒。

基本实现,需要根据自己的数据进行修改

我在 handleClick 方法上写的基本功能是

handleClick(e) {
  const regex = new RegExp(this.state.searchkey, "i");
  let filteredData = data.filter(item => regex.test(item.name));
  if (this.state.dept) {
    filteredData = filteredData.filter(item => item.dept === this.state.dept);
  }
  if (this.state.type) {
    filteredData = filteredData.filter(item => item.type === this.state.type);
  }
  this.setState({ filteredData });
}

PS:这不是一个完美的逻辑 可以优化