我的 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,handlebars 是 1。我需要一个解决方案来找到 #each 的索引。
最佳答案
您可以从 #each
助手的 itemViewClass
获取 contentIndex
{{#each itemViewClass="Em.View"}}
<h3 class="row">{{name}} - <small>{{view.contentIndex}}</small></h3>
{{/each}}
关于javascript - Handlebars 中的索引运算符说 Unexpected token ,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18586020/