我想在durandal.js中添加comfirmationbox
我写了以下代码,但它没有返回Yes或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)
}
答案 0 :(得分:5)
showMessage方法返回一个promise,因此您的代码应如下所示:
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/
答案 1 :(得分:1)
从它所说的here app.showMessage()返回一个promise,这意味着你必须在解析promise时编写if语句,即(在这种情况下)当用户单击yes或否,对话框已关闭。你的代码(对我有用)就像
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
}
});