If statement handlebar.js如果…否则不起作用

If statement handlebar.js如果…否则不起作用,if-statement,handlebars.js,thorax.js,If Statement,Handlebars.js,Thorax.js,我的阵列是: [ { status: failed }, { status: passed } ] my Handlebar.js模板的if…else条件为: <td><a class="{{#each status}} {{#if failed}} fail {{else}} pass {{/if}} {{/each}}"></a></td> 上述情况不起作用。任何帮助都将不胜感激。这里有很多事情

我的阵列是:

[    {    status: failed    },    {    status: passed    }    ]
my Handlebar.js模板的if…else条件为:

<td><a class="{{#each status}} {{#if failed}} fail {{else}} pass {{/if}} {{/each}}"></a></td>


上述情况不起作用。任何帮助都将不胜感激。

这里有很多事情要做。首先,数组中的
失败
通过
是变量。它们是布尔、弦乐还是别的?无论哪种方式,这些变量的值都被传递到模板中,而不是它们的名称,因此
{{{if failed}}
将不起作用,因为它正在寻找一个名为“failed”的变量,而该变量不存在。此外,数组中的每个对象都有一个status键,但是
{{{{each status}}
在一个名为status的数组上迭代,因此也存在不匹配的情况

最后,我认为您的逻辑可能是错误的-如果这样做有效,它将有以下输出:

<td><a class="fail pass"></a></td>
像在这个jsfiddle中:

{{#each status}}<td><a class="{{#if failed}} fail {{else}} pass {{/if}}"></a></td>{{/each}}
{status: [{failed: true}, {failed: false}]}