我有2个选择.
一个为Leagues
一个为一个Divisions
我想根据所选内容创建一个Pipe
过滤器.Divisions
League
提供以下数据.如果我Random Beer League
只选择TwoFour
并且SixPack
应该显示为选择的Divisions
选项.
leagues = [ {id: 1, leagueName: 'Recreation League' }, {id: 2, leagueName: 'Random Beer League' } ]; divisions = [ {id: 1, divisionName: 'SoGreen', leagueId: 1, leagueName: 'Recreation League' }, {id: 2, divisionName: 'Yellow', leagueId: 1, leagueName: 'Recreation League' }, {id: 3, divisionName: 'TwoFour', leagueId: 2, leagueName: 'Random Beer League' }, {id: 4, divisionName: 'SixPack', leagueId: 2, leagueName: 'Random Beer League' } ];
PLUNKER显示设置
*注意 - plunker中的数据是硬编码的,但在我的应用程序中设置了Observable.
我创建了一个自定义管道并用它来过滤部门下拉列表.
@Pipe({ name: 'myfilter', pure: false }) export class MyFilterPipe implements PipeTransform { transform(items: any[], args: any[]): any { return items.filter(item => item.leagueName.indexOf(args.leagueName) > -1); } }
请看看这个Plnkr