我正在使用Backbone.Marionette的ItemView构建一个模态对话框视图,其中包含一个供用户填写的表单。我未能实现的是如何在关闭之前检查状况。这是我一直在使用的结构
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。最近将Backbone和Marionette库升级到最新版本,我发现没有问题。我只是想问一个简单的问题,用户是否已完成其行动但不知道上面的代码有什么问题