车把中的索引运算符表示意外令牌,

index operator in handlebars say Unexpected token ,

本文关键字:表示 意外 令牌 运算符 索引      更新时间:2023-09-26

我的ember应用程序中有#each循环,我想知道循环的索引,所以我尝试使用{{@index}},如下所示:

<script type="text/x-handlebars" data-template-name="column">
<ul>
{{#each item in controller}}
{{@index}}
{{item-rows currentItem=item}}
{{/each}}
</ul>
</script>

但在chrome中,我得到了这个错误:

Uncaught SyntaxError: Unexpected token , handlebars.js:1457

我的ember.js版本是rc8,手把是1。我需要一个解决方案来找到#每个的索引。

您可以从#each助手的itemViewClass获取contentIndex

{{#each itemViewClass="Em.View"}}
   <h3 class="row">{{name}} - <small>{{view.contentIndex}}</small></h3>    
{{/each}}

演示FIDDLE