I've a simple scenario where I return JSON with nested objects with a Rails backend. I'm having trouble accessing the attributes of the nested object.
Example JSON:
[{
category_id: 2,
id: 34,
name: "red",
category: {
name: "color"
}
},
{
category_id: 2,
id: 35,
name: "blue",
category: {
name: "color"
}
}]
Say I want to access category color for item with an id of 35, this works fine in the console:
collection = new App.Collections.Colors()
collection.fetch()
model = collection.get(35)
model.get('category').name
Within my eco templates, I get the error, "Cannot read property 'name' of undefined." However, my template still shows I can access the object with [object Object] if I only indicate
<%= model.get('category') %>
Any ideas? I'm sure I'm not understanding something fundamental.
UPDATED
I realized some category names were nil which was causing the error. The above code should be fine.