0

基于这篇文章:如何根据下拉列表中的多项选择过滤结果?

,如果两个选定的值来自不相邻的列怎么办?

例如,如果两个下拉列表是“名称”和“符号”?

dataSource.filter 是否将通配符作为输入?像“氢*H”

如果没有,我们如何实现这个功能,以便它可以执行 AND 运算符?

4

1 回答 1

1

只需使用类似的功能

  customFiltered() {
    return (data, filter) => {
      if (this.name && this.symbol)
        return data.name == this.name && data.symbol == this.symbol
      if (this.name)
        return data.name == this.name
      if (this.symbol)
        return data.symbol == this.symbol
      return true
    }
  }

那么你只需要

this.dataSource.filterPredicate =this.customFiltered();

您的变量 this.name 和 this.symbol 是您选择的 [(ngModel)]

你可以在stackblitz中看到

于 2019-01-25T07:51:44.173 回答