如何在`hbs`模板中用`index`添加数字

时间:2017-08-22 09:46:07

标签: ember.js handlebars.js

我正在尝试为现有的index值添加一个数字但是我收到了错误。怎么解决这个问题?

以下是我的尝试:tabindex="{{index+1}}"class="digit{{index+1}}"都会抛出错误。

{{#each  cardDigitField as  |field index|}}
    <input type="number" tabindex="{{index+1}}" min="0" max="9" maxlength="1" value='' 
    onKeyUp={{action "numberEntered" index}} 
    onKeyPress={{action "numberInit" }} class="digit{{index+1}}">
{{/each}}

1 个答案:

答案 0 :(得分:1)

您可以从Angular了解模板表达式,但默认情况下Ember不支持模板表达式。 你可以做的是使用Ember模板帮助器。

create your own或使用插件(例如ember-composable-helpers)。

{{#each  cardDigitField as  |field index| }}
    <input type="number" tabindex="{{inc index}}" min="0" max="9" maxlength="1" value='' 
        onKeyUp={{action "numberEntered" index}} 
        onKeyPress={{action "numberInit" }} class="digit{{inc index}}">
{{/each}}