msg*_*msg 2 titanium appcelerator titanium-mobile
我在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();
});
Run Code Online (Sandbox Code Playgroud)
我尝试过如下,但不起作用.
dialog.addEventListener('click',function(e){
alert('You Clicked' + e.source.options);
});
Run Code Online (Sandbox Code Playgroud)
更改您的代码如下
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 ]);
}
Run Code Online (Sandbox Code Playgroud)
希望它能帮助你
| 归档时间: |
|
| 查看次数: |
3571 次 |
| 最近记录: |