带有嵌套对象的Angular Material表过滤器

时间:2019-10-23 14:33:09

标签: angular angular-material

我的对象中有两个数组,导致我可以实际过滤一个数组,但不能过滤第二个数组。

这是我的过滤谓词,适用于区域数组,但不适用于数组propertyType。有人知道我也要过滤第二个数组吗?

this.dataSource.filterPredicate = (data, filter: string)  => {
  const accumulator = (currentTerm, key) => {
    return key === 'district' ? currentTerm + data.district.name : currentTerm + data[key];
  };
  const dataStr = Object.keys(data).reduce(accumulator, '').toLowerCase();
  // Transform the filter by converting it to lowercase and removing whitespace.
  const transformedFilter = filter.trim().toLowerCase();
  return dataStr.indexOf(transformedFilter) !== -1;
};

接口

export interface Property {
   city: string;
   description: string;
   district: District; <-- here
   efficiencyRating: EfficiencyRating; <-- here
   houseno: string;
   id: number;
   name: string;
   propertyType: PropertyType; <-- here 
}

0 个答案:

没有答案