嵌套木偶区域,布局和视图

joe*_*cox 9 backbone.js marionette

我正在尝试将我的Marionette视图与应用程序区域和布局结合使用,但我似乎无法在布局中获取嵌套视图以进行渲染.

编辑:我预计双方OptionsViewBreadcrumbsView在被渲染NavigationLayout,这应该在导航区域进行渲染.但是,根本不渲染导航区域.控制台不显示任何错误.

我的结构如下:

- Navigation region
  - Navigation layout
    - Options region 
    - Breadcrumbs region
- Content region
Run Code Online (Sandbox Code Playgroud)

分配ItemView给导航区域按预期工作.

App = new Backbone.Marionette.Application();
App.addRegions({
    'nav': '#nav',
    'content': '#content'
});

var NavigationLayout = Backbone.Marionette.Layout.extend({
    template: '#nav-template',
    regions: {
        'breadcrumbs': '#breadcrumbs',
        'options': '#options'
    }
});

var BreadcrumbsView = Backbone.Marionette.ItemView.extend({
    template: '#breadcrumbs-template'
});

var OptionsView = Backbone.Marionette.ItemView.extend({
    template: '#options-template'
});

var ContentView = Backbone.Marionette.ItemView.extend({
    template: '#content-template'
});

App.addInitializer(function(options) {
    var navigationLayout = new NavigationLayout();

    App.nav.show(navigationLayout);
    App.content.show(new ContentView());

    navigationLayout.breadcrumbs.show(new BreadcrumbsView());
    navigationLayout.options.show(new OptionsView());
});

$(function() {
    App.start();
});
Run Code Online (Sandbox Code Playgroud)

可以在此处找到简化的测试用例

Der*_*ley 18

好的,终于找到了问题:你不能options在布局中命名一个区域.

布局中定义的所有区域都直接附加到布局实例.所以,这样定义的区域如下:


Layout.extend({
  regions: {
    options: "#options"
  }
});
Run Code Online (Sandbox Code Playgroud)

最终设置layoutInstance.options为Region实例.这是一个问题,因为Backbone.View定义并将其options用于其他目的.

将区域重命名为现有关键字或任何现有视图使用的属性以外的任何内容都将解决此问题.


Layout.extend({
  regions: {
    optionRegion: "#options"
  }
});
Run Code Online (Sandbox Code Playgroud)

在这里工作JSFiddle:http://jsfiddle.net/tegon/64ovLf64/