【问题标题】:How do i dynamically populate an ion-select with an array which was selected from a previous ion-select如何使用从以前的离子选择中选择的数组动态填充离子选择
【发布时间】:2020-05-13 05:55:20
【问题描述】:

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

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

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

    <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>

【问题讨论】:

    标签: angular typescript ionic-framework angular8 ngfor


    【解决方案1】:

    您可以使用(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
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-15
      • 2019-03-03
      • 2017-12-28
      • 2018-09-25
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多