首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >组合多个搜索结果Angular 10

组合多个搜索结果Angular 10
EN

Stack Overflow用户
提问于 2021-09-13 07:47:38
回答 1查看 55关注 0票数 1

我想要像material dataTable filter一样,通过一个输入字段使用名字、手机号码过滤我的数据。构造函数:

代码语言:javascript
运行
复制
  constructor() {
            this.filteredPatient = this.patientsearch.valueChanges
              .pipe(
                startWith(''),
                map(p => p ? this._filterPatient(p) : this.patients.slice())
                    );
          }



    private _filterPatient(value: string): IPatient[] {
    const filterValue = value.toLowerCase();

    const searchByfirstName = this.patients.filter(p => p.firstName.toLowerCase().includes(filterValue));
    const searchBylastName = this.patients.filter(p => p.lastName.toLowerCase().includes(filterValue));
    const searchBymobileNumber = this.patients.filter(p => p.mobileNumber.toLowerCase().includes(filterValue));
    const mergedObj = { ...searchByfirstName, ...searchBymobileNumber };
    return mergedObj;
  }

但这是行不通的。有没有人能建议我如何过滤数据。

EN

回答 1

Stack Overflow用户

发布于 2021-09-13 07:54:46

您可以像下面这样实现:

代码语言:javascript
运行
复制
private _filterPatient(value: string): IPatient[] {
  const filterValue = value.toLowerCase();

  const result = this.patients.filter(
    (p) =>
      p.firstName?.toLowerCase().includes(filterValue) ||
      p.lastName?.toLowerCase().includes(filterValue) ||
      p.mobileNumber?.toLowerCase().includes(filterValue)
  );

  return result;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69159021

复制
相关文章

相似问题

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