angular - 如何使用从以前的离子选择中选择的数组动态填充离子选择
问题描述
所以我得到了一个对象数组,这些对象是具有 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>
在您的 page.ts 中为子类别获取一个变量。
sub_category:any;
selectCategory(catagory){
this.sub_category = category; //populate here
}
推荐阅读
- javascript - 如何通过 get 请求从函数中获取结果?
- mysql - Mysql注释表与多表相关
- three.js - Aframe:获取任何对象的顶点
- java - `java.net.SocketException: Connection reset` 请求代理
- destructuring - 你能解压小马模式匹配中的值吗?
- c# - 缓慢的 API 调用 Azure 应用服务和 Azure 标准数据库 50 (S2) 与实体框架
- python - 是否可以使用 iloc 方法在大数据帧(80000 行,6 列)中找到某些行的索引位置?
- php - php按数量规则组合和排序数组(Laravel 5.6)
- c# - 如何在我的正则表达式中使用 C# 中的未命名正则表达式组?
- spring-boot - 通过 Spring Boot 应用程序发送邮件