[英]PhoneGap confirm callback function
I'm currently working on a mobile application using jQuery Mobile and PhoneGap 2.0.0. 我目前正在使用jQuery Mobile和PhoneGap 2.0.0开发移动应用程序。 The app is an html file with different div elements that represents the screens of the app and a native container is used to display the screens using javascript code.
该应用程序是一个HTML文件,具有不同的div元素,分别表示应用程序的屏幕,并且使用本机容器使用JavaScript代码显示屏幕。
For several actions, I have been using the native alert and confirm functions to interact with the user. 对于几个操作,我一直在使用本机警报和确认功能来与用户交互。 For example:
例如:
function customBeforeMenuItemClick(screen, menuItem) {
if (screen === "APPROVALQUEUE" && menuItem === "Close") {
return (confirm('Do you want to close without submitting changes?'));
}
}
Here the function takes the return from the confirm popup and uses it in an other function (over which I have no control) to process the action of closing or not the app. 在这里,该函数从确认弹出窗口中获取返回值,并将其用于其他函数(我无法控制)以处理关闭或不关闭应用程序的操作。
Now I need to modify the title of the popups and thought of using the Phonegap functions navigator.notification.alert and confirm. 现在,我需要修改弹出窗口的标题,并考虑使用Phonegap函数navigator.notification.alert并确认。 However, these functions are asynchronous and the execution of the script continues.
但是,这些功能是异步的,脚本的执行将继续。
I have tried to use the callback method to return the correct boolean but the function using the confirm popup has alreday finished executing 我尝试使用回调方法返回正确的布尔值,但是使用确认弹出框的函数几乎已经完成执行
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;}
}
In this example code, the popup flashes briefly before disappearing when the app is closed after function toClose() has finished. 在此示例代码中,功能toClose()完成后,在关闭应用程序时,弹出窗口在消失之前短暂闪烁。
I have tried using the callback function to set a global variable that would be used to return the result of the popup but it didn't work. 我尝试使用回调函数设置一个全局变量,该变量将用于返回弹出窗口的结果,但是它不起作用。
Is there a way to get the result of the navigation.notification.confirm ? 有没有办法获得navigation.notification.confirm的结果?
You may close the app like this: 您可以这样关闭应用程序:
// you may alert the callback button to make sure which button sends which index
var YES_BUTTON = 1; // assuming that the 'YES' button will send the index 1
function onConfirmClose(button){
// alert(button); ?
if (button == YES_BUTTON) {
navigator.app.exitApp(); // close the app
}
}
If that still fails, you may take a look at the API Documentation then start from the example for your test. 如果仍然失败,则可以查看API文档,然后从测试示例开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.