我应该如何以及在何处使用模态对话框功能定义区域或函数,以便我可以在视图中的一个或两个指定情况下加载它,例如 through MyApp.modal.show(content)
?
例子:
var ModalRegion = Backbone.Marionette.Region.extend({
el: "#modal",
constructor: function(){
_.bindAll(this);
Backbone.Marionette.Region.prototype.constructor.apply(this, arguments);
this.on("view:show", this.showModal, this);
},
getEl: function(selector){
var $el = $(selector);
$el.on("hidden", this.close);
return $el;
},
showModal: function(view){
view.on("close", this.hideModal, this);
this.$el.modal('show');
},
hideModal: function(){
this.$el.modal('hide');
}
});
在这个视图中如何使用它?
MyApp.Views.Layouts.Unauthenticated = Backbone.Marionette.Layout.extend({
template: 'layouts/unauthenticated',
regions: {
//modal: ModalRegion, //Region must be specified as a selector string or an object with selector property
tabContent: '#tab-content'
},
events: {
'click #showLogin': 'showLogin'
},
views: {},
showLogin: function(){
this.views.login = BD.Views.Unauthenticated.Login;
MyApp.modal.show(new this.views.login);
},