我如何从选择器值获得索引选定
How can I get Index from Picker value selected?
我正在用Appcelerator构建一个应用程序。因此,我使用了一个Picker组件来显示一个值列表。
现在我想知道用户选择的元素的索引是什么
所以我试着这样做:
var indexRow =$.comboDecription.getSelectedRow(0).getZIndex();
您可以使用以下代码:
// first get all columns
var columnsArray = $.comboDecription.getColumns();
// since it is a single column picker, so first index column's rows will be the ones you need.
var allRows = columnsArray[0].rows;
// get the title of first row, getSelectedRow(index) takes column index which is 0 in this case
var currentRowTitle = $.comboDecription.getSelectedRow(0).title;
// get the titles of all rows, these titles will be used to get the index of current title.
// use underscore library 'map' method to iterate over all rows and get their titles in an array
var allRowsTitles = _.map(allRows, function (row) {
return row.title;
});
// *** OR *** you can use underscore _.pluck method
var allRowsTitles = _.pluck(allRows, 'title');
// finally, this is the index of the selected picker row.
var currentSelectedRowIndex = allRowsTitles.indexOf(currentRowTitle);
我知道这是一个漫长的过程,但也有其他的方法,这取决于你的实施过程。尽管如此,我已经向您展示了可以在运行时执行的操作,因此您可以执行与选择器相关的其他操作。
gZindex()返回视图所在的图层。change事件返回当前选择的索引。
相关文章:
- 基于类似索引的queryString的Id选择器
- 将页面元素索引到 JSON 对象?或者jQuery选择器它每次
- 如何在每次点击时更改日期时间选择器的 Z 索引
- :gt()选择器,为变量定义的索引
- 如何将数组索引传递给jquery选择器
- jQuery:忽略选择器的元素的索引
- jquery选择器:如何从某个索引到末尾选择所有li项
- jQuery选择器按表单索引和输入名称
- jQuery-selector在另一个选择器传递的变量中丢失其值并成为索引器
- Jquery使用数组中的索引获取某些选择器的文本值
- 如何在过滤器和选择器中设置索引变量
- 获取jQuery选择器的数组索引
- 为什么我的$(选择器).索引(过滤器选择器)返回不正确的结果
- jQuery .each()函数通过索引访问其他选择器
- jQuery:通过选择器查找后代,并通过索引设置值
- 自定义选择器中的索引不能正常工作
- 我如何从选择器值获得索引选定
- 正索引在addRule中意味着什么(选择器、样式、索引)
- 用选择器和索引重构jQuery
- 在多个元素的选择器中获取元素的索引