javascript - 如何在 Backbone Modal 中使用 cancelEl?

标签 javascript jquery backbone.js modal-dialog

我目前正在将此插件用于模态:http://awkward.github.io/backbone.modal/

它带有一个cancelEl方法来关闭模态,我是这样使用它的:

  var ActionModal = Backbone.Modal.extend({
    template: '#actionable-modal-template',
    cancelEl: '.bbm-btn-close'
  });

这是我正在尝试做的,用伪代码编写:

if (cancelEl.invoked) {
  // Do something
}

伪代码基于这样的假设:cancelEl 导致单击模态背景以及按钮以关闭模态。

如何使用cancelEl方法?

谢谢。

最佳答案

你可以实现beforeCancel或者cancel

  var ActionModal = Backbone.Modal.extend({
    template: '#actionable-modal-template',
    cancelEl: '.bbm-btn-close',
    beforeCancel: function() {
       // stuff
    }
  });

查看源代码,beforeCancel 可用于取消模态关闭:

if (this.beforeCancel) {
  if (this.beforeCancel() === false) {
    return;
  }
}

cancel可以用来实现更多的功能:

if (typeof this.cancel === "function") {
  this.cancel();
}

关于javascript - 如何在 Backbone Modal 中使用 cancelEl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36268625/

相关文章:

javascript - backbone.js View 确定模型的哪个属性发生变化

javascript - nativescript-vue navigatorTo vue 页面 props 已缓存

javascript - getJSON 响应处理

javascript - Angularjs ui-gmap-window 对象数据不呈现

javascript - 如何使用 javascript 变量使用 jQuery 隐藏元素

javascript - 使用引导工具提示进行 Ajax 调用

javascript - Backbone save() 方法 Post 而不是 Put

javascript - 想要将延迟添加到 Keydown 事件

javascript - 在 IE8 中解析 JSON 的奇怪行为

rest - Backbone Send Post 数据编码为查询字符串