I want to populate a collection from an json file, which has other data apart from the array of data items. I came to know that parse function on collection should be used to return the array of data items, but my collection is not getting populated from the json file. When i kept a breakpoint at parse method in firebug, the control is not at all coming there.
This is my code
var m1 = Backbone.Model.extend({
title:'Title1',
tag:'html',
date: 'Today'
})
cll = Backbone.Collection.extend({
url:'/combodata.json?uu',
model:m1,
parse:function(res){
return res.items;
}
});
ci = new cll();
ci.fetch();
The json response will be like this
{
'identifier': 'title',
items:[
{title:'A', tag:"htmlcss", date:'today'},
{title:'AA', tag:"htmlcss", date:'today'},
{title:'B', tag:"htmlcss", date:'today'},
{title:'C', tag:"htmlcss1", date:'today'}
]}
Please point me where I'm wrong.
Not an expert at JSON but I tried to validate your JSON at jsonlint.com. It fails at line 2
Parse error on line 1:
{ 'identifier': 'title
-----^
Expecting 'STRING', '}'
Kindly verify if your JSON is valid or not.
Just checked another site for your JSON validation http://jsonformatter.curiousconcept.com/ and it seems, that string identifiers should be used with double quotes instead of single quotes. Replacing your single quotes with double quotes might help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With