离子(ionChange)获得选定的索引 [英] Ionic (ionChange) get selected index

查看:130
本文介绍了离子(ionChange)获得选定的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道如何使用ionChange事件获取选定的值,但是如何获取选定的索引.例如,如果我要在下拉菜单中选择第三个值,那么如何获取所选的索引(2)而不是所选的值?

So I know how to get the selected value using the ionChange event, but how do I get the selected index. For example if i was to select the 3rd value down in a dropdown how can I get the selected index (2) rather than the value selected?

推荐答案

您可以执行以下操作:-

You can do something like ths:-

<ion-select placeholder="Select One">
      <ion-select-option value="id1">Value1</ion-select-option>
      <ion-select-option value="id2">Value2</ion-select-option>
</ion-select>

通过此操作,当您选择任何特定选项时,然后在其更改事件上,您将获得该对象的ID而不是控制器中的值.

By this when you will select any particular option, then on its change event you will get that object's id instead of the value in the controller.

希望对您有帮助.

这篇关于离子(ionChange)获得选定的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆