What is the {{#each as}} syntax in ember?

你离开我真会死。 提交于 2019-12-11 03:38:18

问题


I came across this question How to set itemController in each as (ember 1.11 beta3)? while trying to figure out some stuff about controllers, and the asker used this syntax inside their {{#each}}

{#each content as |product index|}}
  {{index}}
{{/each}}

I've never seen this before and I couldn't find any documentation on it. Could someone explain what this does?


回答1:


This syntax is block params introduced in Ember 1.10. Following this link will give you more info, but basically it allows you to do iterate on collection still having controller (or components) scope accessible inside.

The index is basically an index here.

{{somePropertyOnController}}
{#each content as |product index|}}
  <!-- index is an index in iteration -->
  {{index}}
  <!-- product is an object in the array / enumeration -->
  {{product}}
  <!-- still have access to controller -->
  {{somePropertyOnController}}
{{/each}}


来源:https://stackoverflow.com/questions/30144035/what-is-the-each-as-syntax-in-ember

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!