我目前正在使用jQuery Mobile和PhoneGap 2.0.0的移动应用程序。 该应用程序是一个带有不同div元素的html文件,代表应用程序的屏幕,并使用本机容器显示使用JavaScript代码的屏幕。PhoneGap确认回调函数
对于多种操作,我一直在使用本地警报和确认功能与用户交互。 例如:
function customBeforeMenuItemClick(screen, menuItem) {
if (screen === "APPROVALQUEUE" && menuItem === "Close") {
return (confirm('Do you want to close without submitting changes?'));
}
}
在这里,函数采用从确认弹出的返回,并在其他函数使用它(在其上我没有控制)来处理关闭的动作或不应用程序。
现在我需要修改弹出窗口的标题,并想到使用Phonegap函数navigator.notification.alert并确认。但是,这些函数是异步的,并且脚本的执行继续。
我曾尝试使用回调方法返回正确的布尔但使用确认弹出的功能alreday执行完毕
function onConfirmClose(button){
return (button == 1);
}
function toClose(){
navigator.notification.confirm("Close?", onConfirmClose,
'Do you want to close', 'yes,no');
}
function customBeforeMenuItemClick(screen, menuItem) {
if (screen === "Start" && menuItem === "Cancel") {
toClose();
}
else {return true;}
}
在此示例代码,弹出短暂闪烁时,应用程序是在消失之前在函数关闭()完成后关闭。
我曾尝试使用回调函数来设置一个全局变量,该变量将用于返回弹出式窗口的结果,但它不起作用。
有没有办法得到navigation.notification.confirm的结果?
当'onConfirmClose'出现时''button'里有什么? –
按钮是在notification.confirm上按下的按钮的索引(即1代表“是”,2代表“否”)。 以下是来自科尔多瓦网站的文档http://cordova.apache.org/docs/en/2.0.0/cordova_notification_notification.md.html – Khalid
是的我知道,但*在你的代码*中,它是否到达那里?它有什么?那么证明什么不起作用总是比较容易 –