I have a composite view that throws the following error when a model is added to the collection of views: Uncaught ItemViewContainerMissingError: Missing itemViewContainer
Here is my composite:
// 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); } });
I found that adding the following code to initialization before binding to the collection fixes the error:
var html = this.renderModel(); this.$el.html(html);
I'm not sure why I need these two lines of code when I have other composite views that work fine. The following is an example of a working composite view:
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); } });
There seems to be no difference between the views, so I'm not sure what happened.
user1473339
source share