I am trying to load a json file into a backbone model like so :
var Feed = Backbone.Model.extend();
var FeedCollection = Backbone.Collection.extend({
model: Feed,
url:'feed.json'
var feeds = new FeedCollection();
feeds.fetch({success : function() {
console.log(feeds);
}})
The first log returns the JSON obect within the file, just returns an object without the json data.
You should try and mention a few more properties for your fetch call. Try passing in the method
argument and the dataType
argument. If you are getting JSONP, try passing in callback
too. Here is a code snippet I use that should help you out -
feeds.fetch({
method:"GET",
dataType: 'jsonp',
jsonp: 'callback'
}).complete(function(resp) {
// Do stuff here
});
You're overriding the parse
function and not returning anything from it for the collection to add to itself. Removing parse
from FeedCollection
should allow it to populate.
Alternatively, return from that parse
whatever properties you need from the server response to define your collection.