Titanium 无法从钛设备加速器的option对话框中获取所选选项?

Titanium 无法从钛设备加速器的option对话框中获取所选选项?,titanium,appcelerator,titanium-mobile,Titanium,Appcelerator,Titanium Mobile,我用钛制作了一个OptionDialog。我从动态数组中添加了这些选项列表。如何在单击对话框中的任何项目时获取特定选项值 var View = Ti.UI.createTextField({ height : '60dp', width : '90%', value : 'click here' )}; myArray = ['Lion','Tiger','Cat','Elephant','Dog']; var opts = { cancel: 2, options: myArray

我用钛制作了一个OptionDialog。我从动态数组中添加了这些选项列表。如何在单击对话框中的任何项目时获取特定选项值

var View = Ti.UI.createTextField({
height : '60dp',
width : '90%',
value : 'click here'
)};

myArray = ['Lion','Tiger','Cat','Elephant','Dog'];

var opts = {
  cancel: 2,
  options: myArray,
  selectedIndex: 2,
  destructive: 0,
};

var dialog;
View.addEventListener('click',function(){
    dialog = Ti.UI.createOptionDialog(opts).show();
});
我试过下面的方法,但不起作用

dialog.addEventListener('click',function(e){
    alert('You Clicked' + e.source.options);
});
对话框事件侦听器显示所选择的提供的选项数组(
myArray
),而不是选项本身

假设已定义数组,请尝试以下操作:

var myArray = ['Lion','Tiger','Cat','Elephant','Dog'];

....

dialog.addEventListener('click',function(e){
    alert('You Clicked' + myArray[e.index]);
});

这将从所选的
myArray
向选项发出警报。

如下更改代码

var myArray = ['Lion','Tiger','Cat','Elephant','Dog'];

var opts = {
  cancel: 2,
  options: myArray,
  selectedIndex: 2,
  destructive: 0,
};

var dialog;
View.addEventListener('click',function(){
    dialog = Ti.UI.createOptionDialog(opts);
    dialog.show();
    dialog.addEventListener('click', onSelectDialog);
});

function onSelectDialog(event){
    var selectedIndex = event.source.selectedIndex;
    //OR
    //var selectedIndex = dialog.selectedIndex();
    alert('You have selected' + myArray[selectedIndex ]);
}

希望它对您有所帮助

我已经尝试了上述代码。但下面这行抛出的错误是:“dialog.addEventListener('click',function(e){”未定义在添加侦听器之前您是否实例化了该对话框。是的。我已在View的click事件外部正确声明了它。您使用的是哪个操作系统?Android还是ios?谢谢@Anand//或//var selectedIndex=dialog.getSelectedIndex();两个都可以用。这就是我在那里添加它的原因。