3

I've got a nested object that looks like this:

{
    Level1: {
        Level2_1: 1,
        Level2_2: 2,
    }
}

My web api can return a single JSON object exactly like this one, or it can return an array of those. It turns out my model for one of the controllers is an array of these objects.

When I render the template, I do something like this:

{{#each}}
<p>{{Level1.Level2_1}}</p>
<p>{{Level1.Level2_2}}</p>
{{/each}}

When I click to navigate to another view, I get an error "Cannot read property 'level1' of undefined". It seems to happen when ember tries to destroy? the objects in the chain of elements that were referenced.

The problem is that I'm not sure how to solve this, other than not using nested objects. Any clues?

Edit: I made the property names uppercase to reflect exactly what my web api is returning. It seems like this might have been the problem, can anyone confirm?

2
  • 1
    How many levels of nesting are there? Can you show the route and the way you navigate to another "view" (do you mean route?)? You should be able to use recursion to accomplish this. Commented Mar 6, 2014 at 2:46
  • I somehow played around with my back-end to return camel-case JSON and it started working. Do you think this might have been the problem? Commented Mar 6, 2014 at 3:04

1 Answer 1

3

You're suspicion is correct. Uppercase properties are considered global namespace, not necessarily a property in the current context.

This is more a remnant of Handlebars pre-Ember than a standard that's taught in Ember/Handlebars.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.