首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反应过滤多目标键

反应过滤多目标键
EN

Stack Overflow用户
提问于 2022-08-15 10:26:11
回答 1查看 53关注 0票数 -1

尝试使用Minimals.cc时,我和搜索特性有一个问题,它只包含名称,并且需要扩展到我正在筛选的对象(filterAll)的其他键。以下是代码:

代码语言:javascript
运行
复制
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,但是它没有起作用(至少对我这样做的方式是这样的)。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2022-08-15 11:00:12

在尝试了更多之后,这个问题的答案是:

代码语言:javascript
运行
复制
if (filterAll) {
    tableData = tableData.filter((item) => (item.name.toLowerCase().indexOf(filterAll.toLowerCase()) && item.circle_name.toLowerCase().indexOf(filterAll.toLowerCase())) !== -1);
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73359704

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档