有谁知道如何过滤出出现在angular 2下拉列表中的报告结果。我目前正试图在模板* ngFor中做到这一点,但没有运气。我也会尝试一个自定义管道。数据来自JSON数组。在下面的对象我想只显示的“国有实体”Angular 2过滤掉重复出现的下拉菜单
我的数据对象的一个实例
items[
{
"currentBUName":"Financial Services"
}
{
"currentBUName":"State Owned Entities"
}
{
"currentBUName":"State Owned Entities"
}
]
我的TS码提取
<ion-item>
<ion-label>Please select current business unit</ion-label>
<ion-select [(ngModel)]="selectedValue">
<ion-option *ngFor="let indexx of this.items;"[value]="indexx">{{indexx.currentBUName}}</ion-option>
</ion-select>
</ion-item>
感谢您的回复,但我最终使用了这个函数t hanks从这个链接Yoav Schniederman http://stackoverflow.com/questions/41867448/in-angular2-ngfor-iteration-how-do-i-output-only-unique-values-from-the-array'transform() {this.items!== undefined && this.items!== null} console.log(_。uniqBy(this.items,'currentBUName')); this.currentBUvals = _.uniqBy(this.items,'currentBUName'); return _.uniqBy(this.items,'currentBUName'); } return this.items; }' – eohdev