1

My example :

var stooges = [{ name: 'moe', age: 44, userid: 1}, 
               { name: 'larry', age: 44, userid: 2}, 
               { name: 'curly', age: 44, userid: 3}];





var StoogeModel = Backbone.Model.extend({});


var StoogeCollection = Backbone.Collection.extend({
  model: StoogeModel
});



var StoogeItemView = Backbone.Marionette.ItemView.extend({
  tagName: "tr",
  template: '#stooge-template'
});

var StoogesCollectionView = Backbone.Marionette.CollectionView.extend({
  tagName: "table",
  childView: StoogeItemView
});






var myStooges = new StoogeCollection(stooges);

var myStoogesView = new StoogesCollectionView({ collection: myStooges  });


myStoogesView.render();

document.body.appendChild(myStoogesView.el);

This example I read in topic backbone.js collection view example using marionette template but I have error:

marionette_backbone.js:1299 Uncaught NoItemViewError: An itemView must be specified

Help me please.

Community
  • 1
  • 1
zloctb
  • 10,592
  • 8
  • 70
  • 89
  • 1
    Which version of marionette are you using? – Cyclone Sep 12 '16 at 13:08
  • I am not sure, but it could be because of some version mismatch, I copy pasted your code in [this fiddle](https://jsfiddle.net/cyclone/f70z64ef/1/), added libraries and it seems to be working. – Cyclone Sep 12 '16 at 13:22

1 Answers1

2

You're using Marionette 1.x as a dependency in your project, but you're attempting to use 2.x interfaces. In 1.x CollectionViews used an "itemView", while 2.x changed the naming to "childView"

Changing your StoogesCollectionView definition to use the itemView naming should fix your issue:

var StoogesCollectionView = Backbone.Marionette.CollectionView.extend({
  tagName: "table",
  itemView: StoogeItemView
});

Alternatively, you can upgrade Marionette to a newer version.

Lochlan
  • 2,666
  • 3
  • 23
  • 25