Titanium 将选项设置为“选项”对话框

Titanium 将选项设置为“选项”对话框,titanium,titanium-mobile,options,Titanium,Titanium Mobile,Options,我从服务器获取了一个JSON字符串: genre [ 'type1', 'type2', 'type3', 'type4' ] 我想获取数组类型中的值,以添加到选项_对话框中的选项。我声明: var genreArr=[]; for(var i=0;i<genre.length;i++) { genreArr.push(genre[i])); } 但是当单击选项对话框时,它不会在数组genrirr中显示值。您能帮助我吗?Thankoptions是一个仅用于创建的属性,如中所

我从服务器获取了一个JSON字符串:

genre [
 'type1',
 'type2',
 'type3',
 'type4'
]

我想获取数组类型中的值,以添加到选项_对话框中的选项。我声明:

var genreArr=[];
for(var i=0;i<genre.length;i++) 
{
 genreArr.push(genre[i]));
}

但是当单击选项对话框时,它不会在数组genrirr中显示值。您能帮助我吗?Thank

options
是一个仅用于创建的属性,如中所指定。必须将其传递给createOptionDialog调用,如下所示

var genre = [
    'type1',
    'type2',
    'type3',
    'type4'
];

var dialog = Ti.UI.createOptionDialog({
    options: genre,
    title: 'Pick a Genre'
});
dialog.addEventListener('click', function(evt)
{
    alert('You picked ' + genre[evt.index]);
});
dialog.show();

您可以使用我在代码中使用的方式

   var genre = [
    'type1',
    'type2',
    'type3',
    'type4'
];
//调用onclick listener中的选项对话框

var dialog = Ti.UI.createOptionDialog(genre).show();
var win=tianium.UI.createWindow({
标题:“提示设备振动”,
背景颜色:“FFFFFF”
});
var label=Titanium.UI.createLabel({
文本:“您的选择将显示在此处”,
宽度:“自动”,
高度:“自动”
});
//选项对话框的创建和处理与警报对话框非常相似
var colorDialog=tianium.UI.createOptionDialog({
标题:“你喜欢什么颜色?”,
选项:[“黄色”、“给我惊喜”、“不谢谢”],
cancel:2//选项数组中的索引,用于定义哪些按钮是取消按钮
});
var optionButton=Titanium.UI.createButton({
标题:“选项对话框!”,
身高:48,
宽度:120,
底数:12
});
colorDialog.addEventListener(“单击”,函数(e){
如果(e.指数<2){
如果(e.index==0){
win.backgroundColor=“#FFCC00”;
}否则如果(e.index==1){
win.backgroundColor=“#329FF0”;
}
//通过e.index访问按钮索引
//将该索引与e.source.buttonNames一起使用,返回点击的按钮名称:e.source.buttonNames[e.index]
label.text=“您点击了索引”+e.index;
}否则{
label.text=“Aww外壳…”;
}
});
optionButton.addEventListener(“单击”),函数(e){
colorDialog.show();
});
添加(标签);
win.add(选项按钮);
win.open();

事件处理程序在哪里?哪个执行
选项\u dialog.show()
,您的目标设备是什么?而且在
genreArr.push(体裁[i])中似乎有一个额外的“)”你能试着向我解释一下为什么这个代码在iOS上对我有效吗<代码>var win=Ti.UI.createWindow({})win.open()var showopt=Ti.UI.createButton({title:“Show Options”})showopt.addEventListener(“单击”,函数(){opt.Show();})win.add(showopt)optar=[“测试”,“测试1”,“测试2”]var opt=Ti.UI.createOptionDialog({//Options:optors})opt.options=opttarr
Thank=)与规范不符。如果它回答了您的问题,可能需要打勾。Thank=)好的,因此它可能对某些人有效,而对某些人无效,但您应该将其用作创作选项?是的,将其用作创作参数。这在所有平台上都适用。
var dialog = Ti.UI.createOptionDialog(genre).show();
var win = Titanium.UI.createWindow({
    title:"Prompting the Device to Vibrate",
    backgroundColor:"#FFFFFF"
});

var label = Titanium.UI.createLabel({
    text:"Your choice will appear here",
    width:"auto",
    height:"auto"
});

//The option dialog is very similar to the alert dialog in its creation and handling
var colorDialog = Titanium.UI.createOptionDialog({
    title:"What color do you like?",
    options: ["Yellow","Surprise me","No thanks"],
    cancel:2//The index in the options array that defines which of the buttons is a cancel button
});

var optionButton = Titanium.UI.createButton({
    title:"Option Dialog!",
    height:48,
    width:120,
    bottom:12
});

colorDialog.addEventListener("click",function(e){
    if(e.index < 2){
        if(e.index === 0){
            win.backgroundColor = "#FFCC00";
        }else if(e.index === 1){
            win.backgroundColor = "#329FF0";
        }

    //Access the button index via e.index
    //Use that index with e.source.buttonNames to return th button name tapped: e.source.buttonNames[e.index]
    label.text = "You tapped index " + e.index;

    }else{
        label.text = "Aww shucks...";
    }

});

optionButton.addEventListener("click",function(e){
    colorDialog.show();
});


win.add(label);
win.add(optionButton);
win.open();