我有这个代码,它过滤我的数据。我在问我,是否有一种方法可以不显式过滤每个字段 ( id
, mandant
, zonenlogik
...)。也许有更流畅的方法来在所有字段上设置过滤器而不显式调用它们?
let filteredList = this.state.freights.filter((freight) => {
if (freight.id.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.mandant.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.zonenlogik.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.frachtart_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.transportart_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.spedit_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.spedit2_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
if (freight.lager_nr.toLowerCase().indexOf(this.state.search.toLowerCase()) !== -1) {
return freight;
}
});