ember中的{{#each as}}语法是什么? [英] What is the {{#each as}} syntax in ember?

查看:294
本文介绍了ember中的{{#each as}}语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个问题如何在尝试找出一些关于控制器的东西时,将itemController设置为(ember 1.11 beta3)?,而asker在他们的 {{#each}}

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?

推荐答案

这个语法是块参数 在Ember 1.10中引入。以下这个链接将给你更多的信息,但基本上它允许你执行迭代仍然有控制器(或组件)范围可访问内部。

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

这篇关于ember中的{{#each as}}语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆