获取ionic4中ion-select-option的名称

时间:2019-09-12 06:08:09

标签: javascript ionic-framework ionic4

我无法从ion-select中获得名称。我可以使用[(ngmodel)]从ion-select-option中获取值。但是我可以找到如何从所选的ion-select-option中获得名称。

<ion-item>
      <ion-select placeholder="Select User"  [(ngModel)]="selectedUser" (ionChange)="selectedUser1(selectedUser)" style="width:100%;max-width:100%;">              
          <ion-select-option *ngFor="let item of user" value="{{item.pos_id}}">{{item.pos_name}}</ion-select-option>
        </ion-select>
    </ion-item>

我需要在打字稿变量中获取{{item.pos_name}}-名称。请帮助我获得所选离子选择选项的名称

1 个答案:

答案 0 :(得分:1)

1选项:您可以遍历User数组以查找名称和其他类似信息。

selectedUser1(selectedUser){
 this.user.map(val, index){
   if(selectedUser == val.pos_id){
     console.log(val); // this will print your complete object of user.
  }
 }
}

2选项:将名称作为ID传递给Value。

<ion-select-option *ngFor="let item of user" value="{{item.pos_id}}, {{item.pos_name}}">{{item.pos_name}}</ion-select-option>
 您将在您的selectedUser ngModel中获得id和Name。您可以根据需要将其拆分。