javascript - 获取ionic4中离子选择选项的名称
问题描述
我无法从离子选择中获得名称。我可以使用[(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}}
在 typescript 变量中获取 - 名称。请帮我获取所选离子选择选项的名称
解决方案
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。您可以根据需要拆分它。
推荐阅读
- css - MaterialUI:如何覆盖 InputBase 组件中的 webkit-autofill 样式?
- python - 循环返回输入
- ios - Swift 4/5 设置将代理添加到 WKWebview
- html - 如何使用bootstrap4在小屏幕上将div从div内部移动到它的正下方
- mysql - 如何将 MySQL 日期(时间戳)字段默认为现在
- python - 从自由格式文本中提取文件路径
- javascript - 从 Swagger 生成静态 Javascript 客户端以在 React Native 中使用
- javascript - 组合两个工作脚本不再有效。将短信发送到手机的书签
- javascript - 使用 React-Native 中的按钮从抽屉导航屏幕到抽屉导航屏幕的方法是什么?
- machine-learning - 我应该使用什么分类器根据每个用户购买的月份找出预期的后续购买类别?