Twitter bootstrap 无法检查数据解除引导模式对话框上的条件
我正在使用Backbone.Marionette的ItemView构建一个模态对话框视图,其中包含一个供用户填写的表单。我没有做到的是如何在它关闭之前检查条件。这是我一直使用的结构Twitter bootstrap 无法检查数据解除引导模式对话框上的条件,twitter-bootstrap,backbone.js,marionette,Twitter Bootstrap,Backbone.js,Marionette,我正在使用Backbone.Marionette的ItemView构建一个模态对话框视图,其中包含一个供用户填写的表单。我没有做到的是如何在它关闭之前检查条件。这是我一直使用的结构 define(function (require) { "use strict"; var Marionette = require('backbone.marionette'), tpl = require('text!tpl/ViewPlan/Calibratio
define(function (require) {
"use strict";
var Marionette = require('backbone.marionette'),
tpl = require('text!tpl/ViewPlan/Calibration.html');
return Marionette.ItemView.extend({
tagName: 'div',
template: _.template(tpl),
className: 'modal fade',
onRender: function () {
this.$el.prop('tabindex', '-1');
this.$el.prop('role','dialog');
this.$el.prop('aria-labelledby','myModalLabel');
this.$el.prop('aria-hidden','true').modal({keyboard: false, backdrop: "static"});
},
events: {
'click .close' : 'onDestroy',
'hide.bs.modal' : '_destroying',
'hidden.bs.modal' : 'onDestroy'
},
_destroying: function (e) {
var a = this.ask();
if(!a) {
e.preventDefault();
} else {
this.onDestroy();
}
},
onDestroy: function () {
if(this.$el.is(':visible')) {
this.$el.modal('hide');
} else {
Marionette.ItemView.prototype.destroy.apply(this, arguments);
}
},
ask: function () {
return confirm("Are you sure to cancel this operation and undo?");
}
});
});
代码位于名为modal.js的文件中,该文件使用requireJs。最近将主干和木偶库升级到最新版本,我没有发现任何问题。我只想问一个简单的问题,
隐藏.bs.modal
事件是否未被触发,用户是否已完成其操作,但不知道我上面的代码有什么问题?如果您尝试自己在onRender
函数中绑定它,会发生什么情况?它触发了.el.on('hidden.bs.modal',function(){alert('Hello')})。但不知何故,我不知道如何这个.ask
不会在它应该询问用户的地方触发。hidden.bs.modal
按预期工作在\u
方法的上下文中该是什么?this
是否包含对ask
方法的引用?我确实尝试使用.bindAll()
来this.ask
和\u
。弄不明白为什么它不起作用