错误:CollectionView需要ItemView

时间:2016-09-12 11:03:01

标签: backbone.js marionette

我的例子:

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);

这个例子我在主题backbone.js collection view example using marionette template中读到,但我有错误:

marionette_backbone.js:1299未捕获NoItemViewError:必须指定itemView

请帮帮我。

1 个答案:

答案 0 :(得分:1)

您在项目中使用Marionette 1.x作为依赖项,但您尝试使用2.x接口。 xcpretty,而In 1.x CollectionViews used an "itemView"

更改itemView定义以使用var StoogesCollectionView = Backbone.Marionette.CollectionView.extend({ tagName: "table", itemView: StoogeItemView }); 命名可以解决您的问题:

null

或者,您可以将Marionette升级到更新版本。