1

バックボーンを使い始めたばかりで、JSON データから単純な html リストを生成する際に問題が発生しています。

エラーが発生しています

キャッチされていない TypeError: オブジェクト関数 (){return c.apply(this,arguments)} にはメソッド 'each' がありません

これが私のコードです

var Show = Backbone.Model.extend();

var ShowCollection = Backbone.Collection.extend({

    model: Show,
    url: 'http://192.168.0.7:8081/api/0b08ecef4eda8c6a28b6be3164a96ac8/?cmd=history&type=downloaded&limit=50',

    parse: function(response){
       return response.data;
    }

});

var ItemView = Backbone.View.extend({

  tagName: "li",
  template: $("#item").html(),

  render: function() {
    var templ = _.template(this.template);
    this.$el.html(templ(this.model.toJSON()));
    return this;
  }

});

var ShowView = Backbone.View.extend({

  el: $("#history"),
  initialize: function() {
    this.collection = ShowCollection;
    this.render();
  },
  render: function() {
    this.collection.each(function(item) {
      this.renderItem(item);
    }, this);
  },
  renderItem: function(item) {
    var itemView = new ItemView({ model: item });
    this.$el.append(itemView.render().el); 
  }

});

var history = new ShowView();

ここに私のデータがあります

{
data: [
{
date: "2013-03-16 05:14",
episode: 10,
provider: "-1",
quality: "HD TV",
resource: "bering.sea.gold.s02e10.720p.hdtv.x264-bajskorv.mkv",
resource_path: "/Users/Machine/Tv/Bering.Sea.Gold.S02E10.720p.HDTV.x264-BAJSKORV repost",
season: 2,
show_name: "Bering Sea Gold",
status: "Downloaded",
tvdbid: 254203
}
],
message: "",
result: "success"
}
4

2 に答える 2

2

this.collection = ShowCollection;

する必要があります

this.collection = new ShowCollection();

于 2013-03-17T21:42:09.657 に答える
1

this.collectionインスタンスではなく、拡張された Backbone Collection クラスに割り当てています。については、extend のドキュメントを参照してください。のようなものが必要ですthis.collection = new ShowCollection()

于 2013-03-17T21:47:27.050 に答える