如何从选择选项ionic 3中获得其他价值

时间:2019-11-16 00:43:15

标签: ionic-framework ionic3

我有这样的东西 .html

<ion-item>
    <ion-label>Choose Industry Type</ion-label>
    <ion-select (ionChange)="getOuterName()" [(ngModel)]="getSelectedValue">
        <ion-option *ngFor="let some of someItems" value="{{some.id}}">
            {{some.name}} </ion-option>
    </ion-select>
</ion-item>
<p>{{getSelectedValue}}</p>

.ts

someItems = [{'id': 1, 'name':'Agriculture','othervalue':'123'},
          {'id': 2, 'name':'Chemicals','othervalue':'1234'},
          {'id': 3, 'name':'Pesticides','othervalue':'12345'}];
getOuterName(){
 console.log(this.getSelectedValue);
 let term = this.someItems.filter(item => item.othervalue ===this.getSelectedValue );
}

我可以在不更改 value =“ {{some.id}}” 的情况下在'getSelectedValue'中显示'othervalue'吗?离子选项?

1 个答案:

答案 0 :(得分:0)

您可以做的就是将整个对象绑定到value

html:-

<ion-item>
        <ion-label>Choose Industry Type</ion-label>
        <ion-select (ionChange)="getOuterName()" [(ngModel)]="getSelectedValue"  >
            <ion-option *ngFor="let some of someItems" [value]="some" >
                {{some.name}} </ion-option>
        </ion-select>
    </ion-item>

在.ts中:-

 someItems = [{'id': 1, 'name':'Agriculture','othervalue':'123'},
          {'id': 2, 'name':'Chemicals','othervalue':'1234'},
          {'id': 3, 'name':'Pesticides','othervalue':'12345'}];

getOuterName(){
// Your can call your **this.getSelectedValue** and its properties
 console.log( this.getSelectedValue.id + this.getSelectedValue.name);

 let term = this.someItems.filter(item => item.othervalue ===this.getSelectedValue.othervalue );
}

这样,您可以同时拥有idothervalue