gpt4 book ai didi

titanium - 无法从 Titanium Appcelerator 的 OptionDialog 框中获取选定的选项?

转载 作者:行者123 更新时间:2023-12-02 08:37:19 25 4
gpt4 key购买 nike

我在 Titanium 中创建了一个 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);
});

最佳答案

如下更改代码

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 ]);
}

希望对你有帮助

关于titanium - 无法从 Titanium Appcelerator 的 OptionDialog 框中获取选定的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20125515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com