0

Could you tell me the "best" way to loop through items with an ArrayController in Ember 1.9.1?

Let's take an ordered list of users as our example.

Previously I would have done this:

<ol>
    {{#each itemController='user'}}
    <li>{{name}}</li>
    {{/each}}
</ol>

In version 1.9+ I understand this style has been deprecated.

Question one, am I correct to loop over the model? Like this:

<ol>
    {{#each user in model itemController='user'}}
    <li>{{user.name}}</li>
    {{/each}}
</ol>

Question two, what if I want to use the controller sort functionality? Can I do this:

<ol>
    {{#each user in arrangedContent itemController='user'}}
    <li>{{user.name}}</li>
    {{/each}}
</ol>

Question three, are there any other (more optimal) ways of looping over data with Ember?

Thanks!

1 Answer 1

1

1. Yes

2. Yes

3. Not as of today (due to Handlebars internal functionality).

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

2 Comments

Thanks, Eric. That helps a lot, I have a bug where Ember fails to render when I use arrangedContent but will render if I use model. I couldn't work out if the issue was my template or my controller. Sounds like the controller!
Ember is a bit iffy to render sometimes. Make sure arrangedContent is populated before the Controller starts to render it's view(s). Typically you can have your custom-array depend on some model-value (by .observes()). Then it will be re-renderd when that asynchronous have loaded.

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.