为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

达令说 2021-10-14 10:17:52
我无法从离子选择中获取名称。我可以使用[(ngmodel)]. 但是,我可以找到如何从选定的离子选择选项中获取名称。<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 回答

?
斯蒂芬大帝

TA贡献1827条经验 获得超8个赞

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>

您将在selectedUserngModel 中获得 id 和 Name 。您可以根据需要拆分它。


查看完整回答
反对 回复 2021-10-14
  • 1 回答
  • 0 关注
  • 236 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信