Why {{array.[index]}} not working


#1

{{#each array as |item index|}}

{{anotherArray.[index]}}

It can not work.

Unless replacing index with explicit number

{{anotherArray.[0]}}

{{/each}}

Do I miss something?


#2

Ember does not support all of handlebars syntax, this is one example.

You can do this with a helper though, simple version might look like:

App.ObjectAtHelper = Ember.Helper.helper(function([ array, index]) {
  return array[index];
});

JSBin Demo


#3

What about

{{#each array key="@index" as |item|}}

?


#4

Thank you.

Just think there should be a built-in way doing that thing.

Customize helper is very useful.

But I think ember.js should include those very very generic helpers to official helpers. It’s better than that everyone has to do this.


#5

Try the get helper which has become available in Ember 2.0:

{{get anotherArray index}}

#6

A related open issue in htmlbars:


#7

If you get an error about index needing to be a string, simply do this: (get items (concat index ""))