1

该应用程序有一个删除 dblog 的按钮。当用户点击按钮时,我要求确认,然后继续删除。

我正在使用 navigator.notification.confirm 询问用户

这是我的代码 -

function deleteLog()
{

    navigator.notification.confirm(
    "Are you sure you want delete?",
    function(buttonIndex){
        if(buttonIndex==1)
        {
            console.log("User has cancelled");
            return;
        }
    },
    "Confirmation",
    "Cancel, Delete");

    console.log("User has confirmed Delete");


}

但是,即使在用户单击取消或删除之前,我也会收到“用户已确认”消息。我尝试在上面添加一个 else 语句,但仍然没有运气。

有什么问题?

编辑:更多信息 -

我喜欢的顺序是 Single Thread === Press Delete -> Ask for Confirmation -> User Pressed Delete -> Delete dbLog。

发生了什么 按 Delete --> 线程一 == 请求确认线程二(按 Delete 后)--> 删除数据库日志

4

1 回答 1

2

通过将console.log(“用户已确认删除”)放在回调之外,您基本上是在告诉程序无论用户按下什么都运行console.log。

我会去掉确认功能以获得更好的可用性,并这样写:

function deleteLog() {
    navigator.notification.confirm(
        'Are you sure you want delete?', // message
        onConfirm,                       // callback to invoke with index of button
        'Confirmation',                  // title
        'Cancel,Delete'                  // buttonLabels
    );
}

//on button press, the onConfirm function is called
function onConfirm(button) {
    //console.log('You selected button ' + button);
    if(button == 1){
        //pressed "cancel"
        console.log("User has cancelled");
    }
    else if(button == 2){
        //pressed "delete"
        console.log("User has confirmed Delete");
    }
}

这行得通。

于 2013-03-03T10:46:09.870 回答