【问题标题】:Error : CollectionView require ItemView错误:CollectionView 需要 ItemView
【发布时间】:2016-09-12 11:03:00
【问题描述】:

我的例子:

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 中阅读了这个示例,但我有错误:

ma​​rionette_backbone.js:1299 未捕获的 NoItemViewError:必须指定 itemView

请帮帮我。

【问题讨论】:

  • 你用的是哪个版本的木偶?
  • 我不确定,但可能是因为某些版本不匹配,我将您的代码复制粘贴到this fiddle,添加了库,它似乎可以正常工作。

标签: backbone.js marionette


【解决方案1】:

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

将您的 StoogesCollectionView 定义更改为使用 itemView 命名应该可以解决您的问题:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-06
    • 2017-11-08
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    • 2016-04-29
    • 2012-06-17
    • 1970-01-01
    相关资源
    最近更新 更多