I’ve been trying to learn backbone.js these days. What I’ve is a model and a collection. The model has some default properties defined in it which I want to fetch within a collection. This is my code:
var model = Backbone.Model.extend({
defaults : {
done : true
}
});
var collection = Backbone.Collection.extend({
model : model,
pickMe : function () {
log(this.model.get('done')); //return undefined
}
});
var col = new collection();
col.pickMe();
How do I call methods defined in my model from collection? Am I doing wrong here?
The basic setup of Backbone is this :
You have models which are part of collection(s). So here in your setup you have a model constructor
modeland collection constructorcollection, but you have no models in your collection and if you have any models they will be an array, so your code should be something like thisYou can check the working jsFiddle here : http://jsfiddle.net/S8tHk/1/