Hi i have a json file that looks like this:
{
"links_1": [
{
"navn": "somename",
"link": "http://www.domane.com"
},
{
"navn": "somename",
"link": "http://www.domane.com"
},
{
"navn": "somename",
"link": "http://www.domane.com"
}
],
"links_2": [
{
"navn": "someothername",
"link": "http://www.domane.com"
},
{
"navn": "someothername",
"link": "http://www.domane.com"
},
{
"navn": "someothername",
"link": "http://www.domane.com"
}
]
}
Then i have my Collection class.
Now i want to create a new collection that only contains the links_1 array from the json file.
And another new collection that contains the links_2 array from the json file.
How do i accomplish that?
var col = new Collection( Collection.prototype.parse = function(response){
return response.links_1;
}
So to illustrate further, i want my fetch to get specific json data objects.
var col = new Collection();
col.fetch(links_1); // here i only want to get links_1 json data
var col2 = new Collection();
col2.fetch(links_2); // here i only want to get links_2 json data
any help would be great.
You’re on the right track with trying to override
parse, you’re just doing it incorrectly. Try:Edit: To select the field you want to extract on instance-to-instance basis, you can pass a custom option in the
fetchoptions. The options are passed toparse: