获取 ionic4 中 ion-select-option 的名称
Get the name of the ion-select-option in ionic4
我无法从 ion-select 中获取名称。我可以使用 [(ngmodel)]
从 ion-select-option 中获取值。但是我可以找到如何从 selected ion-select-选项中获取名称。
<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}}
- typescript 变量中的名称。请帮助我获得 selected ion-select-option
的名称
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 一起传递。
<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。您可以根据需要拆分它。
我无法从 ion-select 中获取名称。我可以使用 [(ngmodel)]
从 ion-select-option 中获取值。但是我可以找到如何从 selected ion-select-选项中获取名称。
<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}}
- typescript 变量中的名称。请帮助我获得 selected ion-select-option
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 一起传递。
<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。您可以根据需要拆分它。