Javascript 每个都不在主干视图渲染中工作
我刚开始使用主干网,从一些JSON数据生成简单的html列表时遇到了问题 我收到了错误信息 未捕获的TypeError:对象函数(){return c.apply(this,arguments)}没有方法“each” 这是我的代码Javascript 每个都不在主干视图渲染中工作,javascript,json,backbone.js,Javascript,Json,Backbone.js,我刚开始使用主干网,从一些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:
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"
}
this.collection=ShowCollection 应该是
this.collection=new ShowCollection() 您正在将
this.collection
分配给扩展主干集合类,而不是它的实例。有关详细信息,请参阅扩展上的文档。您应该有类似于this.collection=new ShowCollection()
的内容 是的,我用下划线。实际上看这行。。。this.collection=ShowCollection;它可能应该是这样的:collection=newshowcollection();要实例化objectHey@Plasticated,您应该标记答案是否被接受,如果它有助于您解决问题。