.html
:
<ion-select *ngIf="filter_type (ionChange)="choose_type('travels',travels.id,$event)">
<ion-option *ngFor="let travels of filter_type">
{{travels.name}}
</ion-option>
</ion-select>
.ts
:
choose_type(type: string, value: any, event: any) {
let index;
if (event.checked === true) {
this.user_filter[type].push(value);
} else {
index = this.user_filter[type].indexOf(value);
this.user_filter[type].splice(index, 1);
}
}
我试图通过travels.id
,但会出现错误 TypeError: Cannot read property 'id' of undefined
。
在这里,我将附加filter_type数组:
0: {id: "21", name: "AMC"}
1: {id: "151", name: "VBC"}
2: {id: "329", name: "GFS."}
3: {id: "258", name: "Gu"}
也许您可以尝试在离子选项上使用离子。
旅行在离子选择中不确定,因为您的 *ngfor在此级别不应用。
<ion-option *ngFor="let travels of filter_type" (ionSelect)=yourFunction >{{travels.name}}</ion-option>
谢谢你们的评论。让我发布正确的答案。由于我忘记在选项区域投入价值,因此出现了问题。
<ion-select id="filter3" *ngIf="filter_type.travels" (ionChange)="choose_type('travels',$event)" multiple="true">
<ion-option id="filter3" *ngFor="let travels of filter_type.travels " [value]="travels.id">{{travels.name}}</ion-option>
</ion-select>
</ion-item>