我有一个带有取消/关闭按钮的模式。
<button type="button" class="close" data-bind="click: close" aria-hidden="true">×</button>
当用户使用取消关闭对话框时,我想通知主机页用户取消了(而不是提交)表单。我怎样才能做到这一点?
最佳答案
当您在 durandal 中打开模式时,该方法会返回一个 promise ,该 promise 在对话框关闭时得到解决。
来自 http://durandaljs.com/documentation/Showing-Message-Boxes-And-Modals.html 的示例
app.showMessage('This is a message.').then(function(dialogResult){
//do something with the dialog result here
});
使用自定义模式时,您可以在执行dialog.close()时创建自己的dialogResult
所以你会做这样的事情:
submit: function() {
dialog.close( this, "submitted" );
}
close: function() {
dialog.close( this, "closed" );
}
然后在您的主机页面中您的代码将是:
app.showDialog('views/dialogs/confirm').then(function(dialogResult){
if( dialogResult == 'closed' )
// User closed instead of submitting
});
关于javascript - 当在 durandal/knockout 中取消(关闭)模式时通知主机页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33577793/