I am trying to learn backbone.js by populating a collection from a simple JSON file, but I can't get it to work. The AJAX call is made (verified with FireBug), but the toJSON
method returns just undefined.
What am I doing wrong?
theModel = Backbone.Model.extend();
theCollection = Backbone.Collection.extend({
model: aModel,
url: "source.json"
});
theView = Backbone.View.extend({
el: $("#temp"),
initialize: function () {
this.collection = new theCollection();
this.collection.fetch(); // JSON call is made
this.render();
},
render : function () {
$(this.el).html( this.collection.toJSON() ); // Returns blank
}
});
var myView = new theView;
Here's my JSON:
[{
"description": "Lorem ipsum..."
},
{
"description": "Lorem ipsum..."
}]