0
如何以及在哪裏應該使用模態對話框功能來定義區域或功能,以便我可以在視圖中的一個或兩個特定情況下加載它,例如,像通過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);
},