Each {{#each}} with index

what is your intention with getting the index? Is it to “cycle” through class assignments while going through the loop (cos I can’t imagine you somehow styling <li>s specifically by their number?), like how the Rails cycle helper works (ActionView::Helpers::TextHelper)? That would be my own use case for this - and I imagine that most folks’ reason for getting the index would be to do the same.

So I could imagine something like this:

<li {{ bindAttr class='cycle( grey, white )' }}>{{ name }}</li>

Or even as part of the {{linkTo}}:

{{#linkTo user user class='cycle( grey, white )'}}{{ user.name }}{{/linkTo}}

I think having something like this built into Ember would make sense.

1 Like