在木偶的复合视图中出现“Missing'projectViewcontainer'”错误

时间:2013-01-22 16:46:38

标签: marionette

我有一个复合视图,当模型添加到视图集合时会抛出以下错误:Uncaught ItemViewContainerMissingError: Missing itemViewContainer

这是我的compositeView:

// VIEW
B.ScrapeUpdate.View = Backbone.Marionette.CompositeView.extend({
    // ITEM VIEW
    itemView: B.ScrapeUpdateItem.View,

    // ITEM VIEW CONTAINER
    itemViewContainer: 'tbody',

    // TEMPLATE
    template: Handlebars.compile(templates.find('#scrape-update-template').html()),

    // INITIALIZE
    initialize: function(options){
        _.bindAll(this);

        // Bind events
        this.collection.bind('reset', this.renderCollection);
    }
});

我发现在绑定到集合之前在初始化中添加以下代码修复了错误:

    var html = this.renderModel();
    this.$el.html(html);

当我有其他复合视图工作正常时,我不确定为什么我需要这两行代码。以下是工作复合视图的示例:

B.BusinessSearchResults.View = Backbone.Marionette.CompositeView.extend({
    // ITEM VIEW
    itemView:B.Business.View,

    // ITEM VIEW CONTAINER
    itemViewContainer: 'tbody',

    // TEMPLATE
    template: Handlebars.compile(templates.find('#business-search-results-template').html()),

    // INITIALIZE
    initialize: function(options){
        _.bindAll(this);

        // Bind events
        this.collection.bind('reset', this.renderCollection);

    }
});

视图之间似乎没有区别,所以我不确定是什么错。

1 个答案:

答案 0 :(得分:0)


 // INITIALIZE
    initialize: function(options){
        _.bindAll(this);

        // Bind events
        this.collection.bind('reset', this.renderCollection);
    }

不需要这些代码行。 CompositeView为您提供开箱即用的功能。包含此代码可能会导致问题。注释掉this.collection.bind行,看看是否仍然收到错误。

相关问题