在 emberjs 中访问 #each 中的索引 [英] Accessing Index in #each in emberjs

查看:25
本文介绍了在 emberjs 中访问 #each 中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看附件中的代码

http://jsbin.com/atuBaXE/2/

我正在尝试使用 {{@index}} 访问索引,但似乎没有在编译.我认为把手支持这一点

I am trying to access the index using {{@index}} but not seems to be compiling. I think handlebars supports that

{{#each item in model}}
  {{@index}} 
  {{item}}
{{/each}}

它不起作用,我不知道是否支持 {{@index}}

It is not working out for, I can't figure out if the {{@index}} is supported or not

我正在使用

  • Ember.VERSION:1.0.0
  • 把手.版本:1.0.0

推荐答案

UPDATE

由于 这个 PR,现在可以使用带有索引的 each helper,采用新的块参数语法.这在 Canary 上可用,希望在 ember 1.11 中默认启用

Since this PR, it's now possible to use the each helper with index, taking advance of the new block params syntax. This is available on canary and hopefully will be enabled by default in ember 1.11

{{#each model as |item index|}}
  <li>
    Index: {{index}} Content: {{item}}
  </li>
{{/each}}

现场示例

对于旧版本

您可以使用{{_view.contentIndex}}.

{{#each item in model}}
  <li>
    Index: {{_view.contentIndex}} Content: {{item}}
  </li>
{{/each}}

现场示例

这篇关于在 emberjs 中访问 #each 中的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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