如何使用从以前的离子选择中选择的数组动态填充离子选择



所以我得到了一个对象数组,这些对象是具有id,name和subccategory等属性的类别。

我使用 *ngFor 来填充第一个离子选择,这很好。

我需要知道如何使用所选类别中的子类别填充第二个离子选择(第一个离子选择( Iv 试图将所选值作为数组传递,但我显然做错了什么,请帮忙!

<ion-row class="filterItems" color="primary">
<ion-label>Category</ion-label>
<ion-select>
<ion-select-option *ngFor="let catagory of catagories">
{{ catagory.category }}
</ion-select-option>
</ion-select>
</ion-row>
<ion-row>
<ion-label>Sub Category</ion-label>
<ion-select>
<ion-select-option>{{Need the subcatagorys in here}} </ion-select-option>
</ion-select>
</ion-row>

您可以使用(ionChange)事件来填充子类别数组。

<ion-row class="filterItems" color="primary">
<ion-label>Category</ion-label>
<ion-select [(ngModel)]="selecTedValue" (ionChange)="selectCategory(selecTedValue)">  // pass your selecTedValue ngModel as parameter
<ion-select-option *ngFor="let catagory of catagories" value="{{category}}">
{{ catagory.category }}
</ion-select-option>
</ion-select>
</ion-row>
<ion-row>
<ion-label>Sub Category</ion-label>
<ion-select>
<ion-select-option *ngFor="let subCat of sub_category">{{subCat.subCategoryNameOrValue}} </ion-select-option>
</ion-select>
</ion-row>

在您的页面中,ts为子类别获取一个变量。

sub_category:any;

selectCategory(catagory){
this.sub_category = category; //populate here
}

最新更新