我正在研究如何在Angular2中过滤数据数组。
我研究了使用自定义管道,但我觉得这不是我正在寻找的,因为它似乎更适合简单的演示文稿转换,而不是过滤大量的数据。
阵列如下所示:
getLogs(): Array<Logs> { return [ { id: '1',plate: 'plate1',time: 20 },{ id: '1',plate: 'plate2',time: 30 },plate: 'plate3',{ id: '2',plate: 'plate4',plate: 'plate5',plate: 'plate6',time: 30 } ]; }
没有办法使用默认管道。以下是默认支持的管道列表:
https://github.com/angular/angular/blob/master/modules/angular2/src/common/pipes/common_pipes.ts。
import {Injectable,Pipe} from 'angular2/core'; @Pipe({ name: 'myfilter' }) @Injectable() export class MyFilterPipe implements PipeTransform { transform(items: any[],args: any[]): any { return items.filter(item => item.id.indexOf(args[0]) !== -1); } }
并使用它:
import { MyFilterPipe } from './filter-pipe'; (...) @Component({ selector: 'my-component',pipes: [ MyFilterPipe ],template: ` <ul> <li *ngFor="#element of (elements | myfilter:'123')">(...)</li> </ul> ` })
希望它能帮助你,蒂埃里
原文地址:https://www.jb51.cc/angularjs/144075.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。