尝试使用Minimals.cc时,我和搜索特性有一个问题,它只包含名称,并且需要扩展到我正在筛选的对象(filterAll)的其他键。以下是代码:
function applySortFilter({ tableData, comparator, filterName, filterCircle, filterAll }) {
const stabilizedThis = tableData.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
});
tableData = stabilizedThis.map((el) => el[0]);
// this is the one i'm trying to make that should includes both item.name and item.circle_name
if (filterAll) {
tableData = tableData.filter((item) => item.name.toLowerCase().indexOf(filterAll.toLowerCase()) !== -1);
}
if (filterName) {
tableData = tableData.filter((item) => item.name.toLowerCase().indexOf(filterName.toLowerCase()) !== -1);
}
if (filterCircle) {
tableData = tableData.filter((item) => item.circle_name.toLowerCase().indexOf(filterCircle.toLowerCase()) !== -1);
}
return tableData;
}
我试着在filter方法中使用&和_\\来添加item.circle_name和item.name,但是它没有起作用(至少对我这样做的方式是这样的)。提前谢谢。
发布于 2022-08-15 03:00:12
在尝试了更多之后,这个问题的答案是:
if (filterAll) {
tableData = tableData.filter((item) => (item.name.toLowerCase().indexOf(filterAll.toLowerCase()) && item.circle_name.toLowerCase().indexOf(filterAll.toLowerCase())) !== -1);
}
https://stackoverflow.com/questions/73359704
复制相似问题