Ember Handlerbars @如何通过父索引访问内部dict值?

时间:2015-09-16 09:37:17

标签: ember.js ember-cli

@index,索引在模板中不起作用。我完全不知道。因此,我已移至{{_view.contentIndex}}以获取索引值。

问题1:

如何通过父索引访问second_dict值?

比方说,我有两个词组

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}}

1 个答案:

答案 0 :(得分:1)

使用{{get}}帮助程序和自定义{{to-string}}帮助程序:

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

{{get}} helper documentation.