Saturday, 24 August 2013

"this.collection.each is not a function". Shouldn't it simply say "each"?

"this.collection.each is not a function". Shouldn't it simply say "each"?

I really have a two part question.
The console is telling me: "TypeError: this.collection.each is not a
function"
In the short-term I would love to know why my code isn't working.
In the long term I am more interested in knowing why it is not telling me
that "each" is not a function, since that is the method I am trying to
call.
P.S. I have confirmed that JQuery is loading correctly, and before this
code loads, so that is not the problem.
The pertinent javascript is:
$(function(){
var items = [
{ name: 'Abe Lincoln', details: 'Is he that guy from that new
reality show?'},
{ name: 'Captain Planet', details: 'He is our hero'},
{ name: 'Karthus', details: 'Press R'},
{ name: 'Your Mom', details: 'She misses me'},
{ name: 'Teddy Roosevelt', details: 'Makes the most interesting
man in the world look boring'}
];
var itemsCollectionView = new ListView({collection: items});
Backbone.history.start();
});
var ListView = Backbone.View.extend({
el: '#the-list',
initialize: function(){
this.render();
},
render: function(){
this.collection.each(function(model){
this.addOne(model);
}, this);
},
//create an itemview for a model, and add it to the list view
addOne:function(model){
var itemView = new ItemView({model: model});
this.$el.append(itemView.render().el);
}
});

No comments:

Post a Comment