Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用管道过滤器,使其在多种条件下工作_Angular_Filter_Pipes Filters - Fatal编程技术网

Angular 使用管道过滤器,使其在多种条件下工作

Angular 使用管道过滤器,使其在多种条件下工作,angular,filter,pipes-filters,Angular,Filter,Pipes Filters,我有一个管道过滤器,它通过name过滤我的客户列表。我需要添加另一个过滤器,以便客户可以通过账号过滤管道进行过滤: import {Pipe, PipeTransform} from '@angular/core'; @Pipe({ name: 'filter', pure: false }) export class FilterPipe implements PipeTransform { transform(items: any[], term): any { r

我有一个管道过滤器,它通过
name
过滤我的客户列表。我需要添加另一个过滤器,以便客户可以通过
账号
过滤管道进行过滤:

import {Pipe, PipeTransform} from '@angular/core';

@Pipe({
  name: 'filter',
  pure: false
})

export class FilterPipe implements PipeTransform {

  transform(items: any[], term): any {
    return term ? items.filter(item => item.name.toLowerCase().indexOf(term.toLowerCase()) != -1) : items;
  }

}
在我看来,我是这样绑定过滤器的:

<input type="text" class="form-control" placeholder="Name" name="term" [(ngModel)]="term">
<input type="number" class="form-control" placeholder="Account number"> <!--Here I want to make another ngModel-->

<table>
  <tr *ngFor="let client of clients | filter: term | sortBy: 'id'; let i = index"
    <td>{{client.name}}</td>
    <td>{{client.account_number}}</td>
  </tr>
</table>


你可以用单管试试这个

 transform(values: any[], filter: string): any {
    if (!values || !values.length) return [];
    if (!filter) return values;

    filter = filter.toUpperCase();

    if (filter && Array.isArray(values)) {
      const keys = Object.keys(values[0]);
      return values.filter(v => v && keys.some(k => v[k].toUpperCase().indexOf(filter) >= 0));
    }
  }

不幸的是,我得到了一个错误:
error-TypeError:v[k]。toUpperCase不是一个函数
无论我在输入中键入什么,无论是字符串还是数字,我都会得到相同的错误。可以发布数组的示例数据数组看起来像:
[{name:“Alex”,account\u number:123},{name:“Bob”,account\u number:456]
等等。让我们来看看。