Search code examples
ember.jsember-cli

Ember Handlerbars @ How to access inner dict values via parent index?


@index, index is not working inside templates. I dont know exactly. Therefore, I have moved to {{_view.contentIndex}} for getting index value.

Question No 1:

How to access second_dict values via parent index ?

Let say, I have two dicts

first_dict = [{"name":"x"},{"name":"y"},{"name":"z"}]
second_dict = [{"name":"x"},{"name":"y"}]


{{#each first in first_dict}}
   {{_view.contentIndex}} # output as 0,1,2
   ???{{second_dict._view.contentIndex.name}} # how to access second_dict value based on parent index ?
{{/each}}

Solution

  • Use {{get}} helper and custom {{to-string}} helper:

    {{#each first_dict as |first index|}}
      Second dict value: {{get (get second_dict (to-string index)) 'name'}}
    {{/each}}
    

    {{get}} helper documentation.