如何在#each的ember 1.10 HBS中添加“if”条件

时间:2018-02-07 10:11:48

标签: ember.js handlebars.js

您好我想在Ember 1.10的以下代码中选择当前月份作为默认值, 当前月份是控制器中的变量:

public static int testMethod(int rank, int[] array){
    return testMethod(rank, Arrays.stream(array).boxed().toArray(Integer[]::new));
}

public static long testMethod(int rank, long[] array){
    return testMethod(rank, Arrays.stream(array).boxed().toArray(Long[]::new));
}

public static double testMethod(int rank, double[] array){
    return testMethod(rank, Arrays.stream(array).boxed().toArray(Double[]::new));
}

////// HBS ////////////

currentMonth: moment().format("M"),
allMonths: moment.months()

我收到了错误。在这种情况下我们可以添加if条件的另一种方式是什么。

1 个答案:

答案 0 :(得分:0)

Ember使用Handlebars,这是一种尽可能无逻辑的模板语言。 {{#if}}助手只接受布尔变量。例如:

{{#if isCurrentMonth}}
    //current month logic
{{else}}
    //non current month logic
{{/if}}

尽管无逻辑设计听起来很棒,但在使用{{#each}}助手时,您很快就会遇到问题。因此,大多数社区很快就离开了完全无逻辑模板的想法。现在很多人都使用ember-truth-helpers

只需安装它们:

ember install ember-truth-helpers

并使用它们:

{{#if (eq currentMonth month)}}

P.S。你的Ember版很老了;更新到2.18或2.16 LTS。