在钛 Appcelerator 中单击按钮时创建选项对话框
creating optiondialog on button click in titanium appcelerator
我正在创建选项对话框,其中包含右侧的单选按钮。这是我在 kitchensink 中看到的,我试图在其他项目中创建我自己的,但它显示错误,如 applybutton();单击按钮时未定义,我知道 applybutton();是我们必须定义它的功能,但在 kitchensink 中它直接显示了它是怎么回事。
如果我必须定义功能我怎么能走得更远,我应该使用图像吗?请帮助我,我是钛 appcelerator 的新手
Ti.UI.setBackgroundColor('white');
var win = Ti.UI.createWindow({
title: 'Click window to test',
backgroundColor: 'white',
exitOnClose: true,
fullscreen: false
});
var opts = {
cancel: 2,
options: ['Confirm', 'Help', 'Cancel'],
selectedIndex: 2,
destructive: 0,
title: 'Delete File?'
};
var dialog = Titanium.UI.createOptionDialog(opts);
dialog.addEventListener('click',function(e)
{
label.text = 'You selected ' + e.index;
if (e.button) {
label.text += ' button';
} else {
label.text += ' option';
}});
var button1 = Titanium.UI.createButton({
title:'Show Dialog 1',
height:40,
width:200,
top:10
});
button1.addEventListener('click', function()
{
dialog.androidView = null;
applyButtons();
dialog.show();
});
win.add(button1);
win.open();
函数 applyButtons() 最初是在 KitchenSink 示例代码中定义的,无论是在文件顶部还是通过带有 require 语句的 commonjs 模块导入。
如果你想调用和使用这个方法,把它放在最上面作为一个函数表达式eg。
var applyButtons = function() {
// Do something
};
您在 click eventLister 上收到未定义的错误,因为它找不到对此函数的引用。
要么删除/删除对函数的调用,要么将其添加到代码的顶部,无论您希望 applyButtons 做什么。
我正在创建选项对话框,其中包含右侧的单选按钮。这是我在 kitchensink 中看到的,我试图在其他项目中创建我自己的,但它显示错误,如 applybutton();单击按钮时未定义,我知道 applybutton();是我们必须定义它的功能,但在 kitchensink 中它直接显示了它是怎么回事。 如果我必须定义功能我怎么能走得更远,我应该使用图像吗?请帮助我,我是钛 appcelerator 的新手
Ti.UI.setBackgroundColor('white');
var win = Ti.UI.createWindow({
title: 'Click window to test',
backgroundColor: 'white',
exitOnClose: true,
fullscreen: false
});
var opts = {
cancel: 2,
options: ['Confirm', 'Help', 'Cancel'],
selectedIndex: 2,
destructive: 0,
title: 'Delete File?'
};
var dialog = Titanium.UI.createOptionDialog(opts);
dialog.addEventListener('click',function(e)
{
label.text = 'You selected ' + e.index;
if (e.button) {
label.text += ' button';
} else {
label.text += ' option';
}});
var button1 = Titanium.UI.createButton({
title:'Show Dialog 1',
height:40,
width:200,
top:10
});
button1.addEventListener('click', function()
{
dialog.androidView = null;
applyButtons();
dialog.show();
});
win.add(button1);
win.open();
函数 applyButtons() 最初是在 KitchenSink 示例代码中定义的,无论是在文件顶部还是通过带有 require 语句的 commonjs 模块导入。
如果你想调用和使用这个方法,把它放在最上面作为一个函数表达式eg。
var applyButtons = function() {
// Do something
};
您在 click eventLister 上收到未定义的错误,因为它找不到对此函数的引用。
要么删除/删除对函数的调用,要么将其添加到代码的顶部,无论您希望 applyButtons 做什么。