问题描述:

i would like to add comfirmationbox in durandal.js

i wrote following to code , but it is not returning Yes or NO

define(['services/logger', 'durandal/plugins/router', 'durandal/app'], function (logger, router, app) {

if (app.showMessage('Are you sure you want to delete :' + titlename + '?', 'Delete Confirmation', ['Yes', 'No'])) {

DeleteAchievement(self, obj.Soid)

}

网友答案:

the showMessage method returns a promise, so your code should look like:

app.showMessage('Are you sure you want to delete :' + titlename + '?', 'Delete Confirmation', ['Yes', 'No']).then(function(dialogResult){
    if(dialogResult === "Yes"){
        //Your code
    }
});

You can get more info here: http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/

网友答案:

From what it says here app.showMessage() returns a promise, that means you have to write your if statement when the promise has been resolved, that is (in this case) when the user clicks yes or no and the dialog is closed. Your code (which worked for me) would then be like

app.showMessage('Are you sure you want to delete :' + titlename + '?', 'Delete Confirmation', ['Yes', 'No']).then(function (dialogResult) {
            if(dialogResult == 'Yes'){
                 //this is called if user clicked yes
            }else{
                 //this is called if user clicked no
            }
        });
相关阅读:
Top