【发布时间】:2016-10-25 14:10:04
【问题描述】:
由于 Collections 实际上是一个模型,它有属性等等,就像这个例子中一样
var Images = Backbone.Collection.extend({
url: 'https://api.myjson.com/bins/4v2d8'
});
var View = Backbone.View.extend({
el: $('.images'),
initialize: function(){
this.listenTo(this.collection, 'sync', this.render, this); // what is this keyword as the last param here?
},
render: function(){
this.collection.each(function(model){
this.$el.append($('<p>'+model.get('name')+'</>' ));
}, this);
}
});
$(function(){
var images = new View({ collection: new Images() });
images.collection.fetch();
});
http://jsbin.com/gohedeguto/edit?html,js,output
但是为什么这个不起作用?
http://jsbin.com/seyoyeqeku/edit?html,js,output
我将Collection 替换为Model 并传递给视图。我收到了this.model.each of undefined。
【问题讨论】:
-
“因为 Collections 实际上是一个模型” - 什么?您是从哪里/如何得出这个结论的?
-
其实是个假账号
标签: javascript jquery backbone.js