使用Ember Handlebars进行迭代时,获取数组索引的正确方法是什么? [英] What is the correct way of getting the index of an array when iterating over it using Ember Handlebars?

查看:112
本文介绍了使用Ember Handlebars进行迭代时,获取数组索引的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{#each controller.content.assetAllocation.class}}
    {{@index}}
{{/each}}

我试图运行上面的代码,这应该是输出数组的索引,但是会产生一个错误:
未捕获的语法错误:意外的令牌

I'm trying to run the code above, which is supposed to output the index of the array, but it produces an error saying: "Uncaught SyntaxError: Unexpected token , "

推荐答案

解决方案不如我所希望的那么好,但是这样做:

Solution is not as nice as I'd hoped, but this works:

{#each controller.content.assetAllocation.class}}
    {{_view.contentIndex}}
{{/each}}

这篇关于使用Ember Handlebars进行迭代时,获取数组索引的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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