javascript - 当在 durandal/knockout 中取消(关闭)模式时通知主机页面

标签 javascript knockout.js durandal

我有一个带有取消/关闭按钮的模式。

<button type="button" class="close" data-bind="click: close" aria-hidden="true">&times;</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/

相关文章:

javascript - Ember.js 属于/hasMany 与异步的关系

javascript - 类型 'filter' 上不存在属性 'Object'

javascript - 使用注释循环选项时 knockout 重置值

javascript - 面临 knockout 绑定(bind)问题

javascript - 如何从绑定(bind)处理程序中的 ViewModel 调用函数

single-page-application - Durandal:如何在该 View 的 activate() 函数中远离当前 View ?

javascript - “if”语句无法正常运行

c# - 在 IE6/7 中使用 IHTMLElement5/6(适用于 IE8/9)会发生什么?它会转向 IHTMLElement 行为吗?

visual-studio-2012 - Typescript 无法在 Build VS 2012 上编译

使用 Promise 时的 Durandal 启动画面