如何使多列管道过滤?

时间:2017-08-20 18:25:52

标签: angularjs typescript angular2-services

我有这样一个条纹,它只适用于列:不再为作者命名。

export class FilterBook2 implements PipeTransform {

transform(items: Book[], filter: Book): any { if (!items || !filter) { return items; } // filter items array, items which match and return true will be kept, false will be filtered out return items.filter((item) => item.Nazwa.indexOf(filter.Nazwa) || item.Autor.indexOf(filter.Autor) !== -1) }

}

输入日期:

filterargs = {Nazwa:“”,Autor:“”}

1 个答案:

答案 0 :(得分:0)

我认为你试图通过多个参数来过滤书籍。您可以将多个值传递给管道转换函数,如下所示:

<div *ngFor="let book of books | filterBook2 : firstArg : secondArg">
    ...
</div>

并在管道类

export class FilterBook2 implements PipeTransform {
   transform(items: Book[], firstArg: Book, secondArg: any): any {
       // your logic here
   }
}