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

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

问题描述

大家好,请查看附上的代码



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



我试图使用{{@index}}访问索引,但似乎没有编译。我认为手柄支持

  {{#模型中的每个项目}} 
{{@index}}
{{item}}
{{/ each}}

我不知道{{@index}}是否得到支持



我正在使用


解决方案

更新



由于这个PR ,现在可以使用带索引的每个帮助器,推进新的块参数语法。这是可用的金丝雀,希望将在默认情况下启用ember 1.11

  {{每个模型为| item index |} } 
< li>
索引:{{index}}内容:{{item}}
< / li>
{{/ each}}

现场样本



对于旧版本



您可以使用 {{_ view.contentIndex}}

  {{#每个项目在模型}} 
< li>
索引:{{_view.contentIndex}}内容:{{item}}
< / li>
{{/ each}}

现场样本


Hello everyone please check out the code attached

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

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

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

I am using

Ember.VERSION : 1.0.0 Handlebars.VERSION : 1.0.0

Thanks

解决方案

UPDATE

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

Live sample

FOR OLD VERSIONS

You can use {{_view.contentIndex}}.

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

Live sample

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

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