用navigator.notification.confirm传递两个参数?

Cha*_*lie 10 javascript cordova cordova-2.0.0

我正在尝试使用Phonegap通知在我的Phonegap应用中显示错误消息,然后允许用户通过电子邮件发送错误.唯一的问题是我无法将错误消息传递给回调函数,导致电子邮件无效.

我现在的代码如下所示:

function displayError(errormsg) {
    navigator.notification.confirm(
                                   errormsg,
                                   onConfirm,
                                   'Error',
                                   'Submit, Cancel'
                                   );
}
function onConfirm(buttonIndex){
    if (buttonIndex === 1){
        alert(errormsg);
    }

}
Run Code Online (Sandbox Code Playgroud)

哪个被调用displayError("Test"),这会产生错误内容Test.我想,然后传递errormsgonConfirm,但我不知道如何做到这一点,或者如果它是可能的.

我正在考虑的一个可能的解决方案是:

function displayError(errormsg) {
    test = errormsg
    navigator.notification.confirm(
                                   errormsg,
                                   onConfirm,
                                   'Error',
                                   'Submit, Cancel'
                                   );
}
function onConfirm(buttonIndex){
    if (buttonIndex === 1){
        alert(test);
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,errormsg如果显示新错误,则不会更改.我确认了这一点,因为在模拟器设置中,我的应用程序抛出了两个错误.第一个在使用该方法时正常工作,传递test,但接下来的第二个错误使用原始变量,而不是最新的变量.

ahr*_*ren 36

function displayError(errormsg) {
    navigator.notification.confirm(
        errormsg,
        function(buttonIndex){
            onConfirm(buttonIndex, errormsg);
        },
        'Error',
        'Submit, Cancel'
        );
}
function onConfirm(buttonIndex, errormsg){
    if (buttonIndex === 1){
        alert(errormsg);
    }

}
Run Code Online (Sandbox Code Playgroud)

将它包装在匿名函数中怎么样?这样,您可以根据需要传递任意数量的参数,同时保持范围.