【发布时间】:2013-06-28 19:20:59
【问题描述】:
我有一个布局,有一个区域。当布局初始化时,我希望它自动初始化一个预设视图以进入其区域,并在布局本身显示/关闭时显示/关闭它。
来自https://github.com/marionettejs/backbone.marionette/blob/master/docs/marionette.layout.md的当前示例:
AppLayout = Backbone.Marionette.Layout.extend({
template: "#layout-template",
regions: {
mainRegion: "#menu",
content: "#content"
}
});
var layout = new AppLayout();
ParentAppLayout.show(layout); // Render the Layout to a parent
layout.mainRegion.show(new SubView());
这个例子表明必须首先显示布局,然后然后我可以初始化并显示子视图。 (上面,如果我在 layout 本身显示之前显示 SubView,则不会发生任何事情,我假设因为选择器在 DOM 中不存在?)
对于可重复使用的布局,我想将此发送视图显示添加到布局本身中,而不是在使用视图的任何地方手动添加它。如何实现?
AppLayout = Backbone.Marionette.Layout.extend({
template: "#layout-template",
regions: {
mainRegion: "#menu",
content: "#content"
},
initalize: function() {
this.mainRegion.attachView(new SubView());
},
onShow: function() {
this.mainRegion.show(this.mainRegion.currentView);
}
});
var layout = new AppLayout();
ParentAppLayout.show(layout); // Render the Layout to a parent, expecting the child view to also be created automatically
然而,这种方法也没有任何作用 - 没有错误。
【问题讨论】:
标签: marionette