我有一个获取一些数据的骨干集合,但是当我尝试使用它获得的 each 方法迭代集合时
Object [object Array] has no method 'each'
这是该系列的模型:
define (['backbone'],function(Backbone){
return Backbone.Model.extend({
url:'http://some_url/api/post/',
});
});//end define
集合本身:'
define (['backbone','models/Post'],function(Backbone,Post){
return Backbone.Collection.extend ({
model: Post,
initialize: function (model)
{
this.userId = model.userId;
this.start = model.start;
},
url: function ()
{
return "http://some_url.com/api/post?userid=" + this.userId + "&start=" + this.start;
},
parse: function (response)
{
return response;
}
});
});
这是实例化使用集合的视图的调用:
cookieVal = document.cookie.split ("; ");
posts = new PostCol ({userId:id = cookieVal[0].split('=')[1],start:1});
posts.fetch ().success (function (response){
post = new Post({collection:response});
post.render();
console.log (post.el);
});
以及使用该集合的视图的实现:
define (['jquery','underscore','backbone','views/Actor'],function($,_,Backbone,Actor){
return Backbone.View.extend ({
className:'moment mb30',
render: function ()
{
console.log (this.collection);
this.collection.each (function (model){
actor = new Actor ({model:model});
this.$el.append (actor.render().el);
},this);
return this;
}
});
});
为什么每种方法都不起作用,我该如何解决这个问题。