最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Understanding layouts in Marionette for Backbone.js - Stack Overflow

programmeradmin4浏览0评论

I think I may have a fundamental misunderstanding of how Marionette.Layout is intended to be used.

I'm trying to something like this:

The layout includes two Marinotette.ItemViews: The "Explode" ItemView and the "PopStar" ItemView. This layout is designed to always contain these views, so I tried to do this:

var TheLayout = Backbone.Marionette.Layout.extend({
    template: '#the=layout-template',
    regions: {
        explode: '#explode-region',
        popstar: '#popstar-region'
    }
    initialize:function(options){
        _.bindAll(this);

        var explodeView = new ExplodeView();
        this.explode.show(explodeView);        // <-- This throws and exception because the regions are not available yet

    }
})

But it looks like the regions are not available until after the layout is rendered. I tried calling this.render() before adding the views in, but this didn't work. I'm pretty sure the fundamental problem here is that I'm applying the layout in the wrong circumstance.

What should I be doing in this circumstance? When is the correct time to use Marionette.Layout?

Thanks!

I think I may have a fundamental misunderstanding of how Marionette.Layout is intended to be used.

I'm trying to something like this:

The layout includes two Marinotette.ItemViews: The "Explode" ItemView and the "PopStar" ItemView. This layout is designed to always contain these views, so I tried to do this:

var TheLayout = Backbone.Marionette.Layout.extend({
    template: '#the=layout-template',
    regions: {
        explode: '#explode-region',
        popstar: '#popstar-region'
    }
    initialize:function(options){
        _.bindAll(this);

        var explodeView = new ExplodeView();
        this.explode.show(explodeView);        // <-- This throws and exception because the regions are not available yet

    }
})

But it looks like the regions are not available until after the layout is rendered. I tried calling this.render() before adding the views in, but this didn't work. I'm pretty sure the fundamental problem here is that I'm applying the layout in the wrong circumstance.

What should I be doing in this circumstance? When is the correct time to use Marionette.Layout?

Thanks!

Share Improve this question asked Aug 15, 2012 at 17:33 Chris DutrowChris Dutrow 50.4k67 gold badges195 silver badges262 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

Show the region views in the layout's onRender method. Code:

var TheLayout = Backbone.Marionette.Layout.extend({
    template: '#the=layout-template',
    regions: {
        explode: '#explode-region',
        popstar: '#popstar-region'
    }
    onRender: function() {
        var explodeView = new ExplodeView();
        this.explode.show(explodeView);
    }
})

Note that in this case the _.bindAll(this) is not needed.

发布评论

评论列表(0)

  1. 暂无评论