【问题标题】:Return filter search results is not working in angular返回过滤器搜索结果不适用于角度
【发布时间】:2021-11-22 02:03:50
【问题描述】:

我的 Angular 应用程序中有一个搜索框。搜索结果应该返回两个对象值,如 product_name 和 product_content。但在我的应用程序中,它只占用一个对象。但我想为 product_name 和 product_content 应用搜索选项。

filter.pipe.ts:

return products.filter((items) => {
  return (
    items.product_name.toLowerCase().includes(searchText), // Not working
    items.product_content.toLowerCase().includes(searchText) // working
  );
});

那么,如何解决这个问题?如果有人知道帮助找到解决方案。

演示:https://stackblitz.com/edit/angular-selvam-ecommerce-task-mffqdn?file=src%2Fapp%2Fpipes%2Ffilter.pipe.ts

【问题讨论】:

    标签: javascript angular typescript angular8


    【解决方案1】:
    return products.filter((items) => {
      return (
        items.product_name.toLowerCase().includes(searchText.toLowerCase()) ||
        items.product_content.toLowerCase().includes(searchText.toLowerCase()) 
      );
    });
    

    || 代替, 来检查这两个条件。

    【讨论】:

    猜你喜欢
    • 2015-03-31
    • 2020-07-17
    • 2018-12-10
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多