【问题标题】:index operator in handlebars say Unexpected token ,车把中的索引运算符说 Unexpected token ,
【发布时间】:2013-09-06 07:38:30
【问题描述】:

我的 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 的索引。

【问题讨论】:

    标签: javascript ember.js handlebars.js


    【解决方案1】:

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

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

    DEMO FIDDLE

    【讨论】:

    • 知道为什么 Handlebars 与 Ember 一起使用会导致这种情况吗?根据 Handlebars 主页@index 应该可以正常工作。为什么 Ember 会破坏这个?
    • @Sukima AFAIK,Ember 不使用车把助手。 Ember 为eachif 等构建了自己的助手......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 2023-03-15
    • 2020-01-24
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多