1

我收到“没有方法‘结果’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

...

在主干.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 集合似乎很好 - 从服务器填充。我知道这可能很难破译,但也许有人对如何解决问题有一些想法。

4

2 回答 2

2

确保您拥有最新的 underscore.js 版本。在 v1.3.3 中添加了“结果”功能

于 2012-06-28T23:59:51.887 回答
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);
    };
  });
于 2012-06-28T23:16:48.440 回答