Got a server returning a JSON object like so:
{
'key1':'value'
'key2':{
'key2_0':'value'
}
}
And a collection:
var Collection = Backbone.Collection.extend({
url:api.url//which returns the object above
});
var collection = new Collection();
collection.fetch({
success:function(data){
//do something
}
});
Now i need to use certain properties of the collection throughout my application, but say i need key1
, i always have to do collection.at(0).get('key1');//returns 'value'
, because the data returned is stored within the collection, in a new Array at key 0.
Question:
How to directly... collection.get('key1')//now returns undefined... because it is
.
I know i could expose an object to the global scope in the collection success function some_other_var = data.toJSON()[0]
and access the some_other_var
properties directly, but that's not what i'm looking for;