Try to use backbone collection to initialize grabbing the json data, but turns out the data is empty. Does backbone collection automatically parse the json data to the model or we have to manually parse it?
var Book = Backbone.Model.extend({
title:"",
isbn:"",
img:""
});
var Books = Backbone.Collection.extend({
model:Book,
url:'latest.json',
// parse:function(data){
// console.log(data);
// },
initialize: function(){
this.fetch();
}
});
Edited to add in my sample json, I validate with jsonlint.com.
[
{"title":"American Pie","isbn":"345354356","img":"/image/pie.png"},
{"title":"Long Tails","isbn":"567575576g","img":"/image/long_tails.png"},
{"title":"Pirates","isbn":"567575765","img":"/image/pirates.png"}
]
Added in JSFiddle link.
latest.jsonresponse look like? - fguillen/in the beginning of thisurl. - fguillentitle:""are not a proper way to initialize default attributes of a Model. Use Model.defaults instead. - fguillen