Reputation: 6728
I have the following sample json:
{
"camp": [
{
"name": "Name",
"data": [
{
"date": "04/08/2014",
"value": 1000
},
{
"date": "05/08/2014",
"value": 1110
}
]
}
]
}
Here, I'm able to do: model.get("camp")[0]
, but when I try: model.get("camp")[0].get("data")
, I get the following error:
undefined is not a function
Here model is the standard backbone model which extends Backbone.Model
I'm confused what I'm doing wrong !!
Upvotes: 0
Views: 64
Reputation: 1336
You only need to call the model.get() function once. After that, you can treat the returned object just like any other javascript-object. For example, you could do this to get one of the values deep inside the object:
model.get("camp")[0].data[0].value
To achieve what you are trying to get, do this:
model.get("camp")[0].data
Upvotes: 2
Reputation: 221
If you want to acces a property of your json array, you should simply do like this:
var test = json.camp.name
Upvotes: 1