我得到“没有方法”结果'backbone.marionette.js:402错误“。这是跟踪:
Uncaught TypeError: Object function (obj) { return new wrapper(obj); } has no method 'result' backbone.marionette.js:402
Marionette.CollectionView.Marionette.View.extend.buildItemView backbone.marionette.js:402
Marionette.CollectionView.Marionette.View.extend.addItemView backbone.marionette.js:360
Marionette.CollectionView.Marionette.View.extend.showCollection backbone.marionette.js:314
...
在backbone.marionette.js中:
// Build an `itemView` for every model in the collection.
buildItemView: function(item, ItemView){
var itemViewOptions = _.result(this, "itemViewOptions");
***Uncaught TypeError: Object function (obj) { return new wrapper(obj); } has no method 'result' ***
var options = _.extend({model: item}, itemViewOptions);
var view = new ItemView(options);
return view;
backbone. },
我的通话代码:
MyApp.module("CatalogsApp.Pasteboard", function(Pasteboard, MyApp, Backbone, Marionette, $, _) {
var CatalogListView, CatalogView;
CatalogView = Marionette.ItemView.extend({
tagName: "div",
className: "catalog-cell",
template: "catalogs/catalog"
});
CatalogListView = Marionette.CollectionView.extend({
tagName: "div",
className: "paste-board",
itemView: catalogView
});
Pasteboard.showCatalogs = function(catalogList) {
var catalogListView;
catalogListView = new CatalogListView({
collection: catalogList
});
return MyApp.layout.main.show(catalogListView);
};
});
如果有人有任何线索可能导致类型错误的问题 - 很高兴得到想法。我几乎可以告诉他。 catalogList集合似乎很好 - 从服务器填充。我知道这可能很难破译,但也许有人知道如何解决问题。
答案 0 :(得分:2)
确保您拥有最新的underscore.js版本。 '结果'功能已添加到v1.3.3
中答案 1 :(得分:0)
执行此操作时,您将覆盖您的班级定义var catalogListView;
。
惯例是为您的类定义大写名称,如下所示:
MyApp.module("CatalogsApp.Pasteboard", function(Pasteboard, MyApp, Backbone, Marionette, $, _) {
var CatalogListView, CatalogView;
CatalogView = Marionette.ItemView.extend({
tagName: "div",
className: "catalog-cell",
template: "catalogs/catalog"
});
CatalogListView = Marionette.CollectionView.extend({
tagName: "div",
className: "paste-board",
itemView: CatalogView
});
Pasteboard.showCatalogs = function(catalogList) {
var catalogListView;
catalogListView = new CatalogListView({
collection: catalogList
});
return MyApp.layout.main.show(catalogListView);
};
});