2

我想在 durandal.js 中添加确认框

我写了以下代码,但它没有返回是或否

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)
            }
4

2 回答 2

5

showMessage 方法返回一个承诺,因此您的代码应如下所示:

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

您可以在此处获取更多信息:http: //durandaljs.com/documentation/Showing-Message-Boxes-And-Modals/

于 2013-08-29T10:08:44.210 回答
1

这里所说的 app.showMessage() 返回一个承诺,这意味着您必须在承诺已解决时编写 if 语句,即(在这种情况下)当用户单击是或否并关闭对话框时。你的代码(对我有用)就像

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
            }
        });
于 2013-08-29T10:12:27.247 回答