在Ionic中动态分配数据到值

时间:2017-09-13 06:58:47

标签: angular ionic-framework ionic2 ionic3

我正在运行for loop内部行,并希望从 filterData value字段分配数据。我不想动态地为数据分配数据。

<ion-row *ngFor="let type of filterData">
    <ion-segment [(ngModel)]="selectedSegment" (ionChange)="onSegmentChanged($event)">
       <ion-segment-button value="Must be came from *ngFor">
        {{type.key}}
       </ion-segment-button>
    </ion-segment>
    </ion-row>

filterData数组成立:

this.filterData=[
  {"key":"Budget","value":"a1","type":"bar","labelid":"17"},
  {"key":"Parking Capacity","value":"a2","type":"checkbox","labelid":"12"},
  {"key":"Venue","value":"a3","type":"checkbox","labelid":"3"},
  {"key":"No.of Rooms","value":"a4","type":"checkbox","labelid":"15"},
  {"key":"Max.Capacity","value":"a5","type":"bar","labelid":"1"},
  {"key":"Function Type","value":"a6","type":"checkbox","labelid":"11"}];

我想分配json元素值字段中的值数据,但不能这样做。

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以ion-segment-button"value={{type.value}}"将值绑定到[value]="type.value"

<ion-segment-button [value]="type.value">
  {{type.key}}
</ion-segment-button>

<ion-segment-button value="{{type.value}}">
  {{type.key}}
</ion-segment-button>

请参阅 working demo