我有一些看起来像这样的测试数据:
{
"firstName":"Ben",
"products": [{
"name": "first product",
"position": 0
}, {
"name": "second product",
"position": 1
}, {
"name": "third product",
"position": 2
}]
}
在我的模板中,我有这样的东西:
<p>Hi {{firstName}}</p>
哪个工作正常。现在我想循环浏览我的产品
所以我尝试了这个:
{{#each products}}
{{#if this.position == 0}}
<h1>{{this.name}}</h1>
{{else}}
<h2>{{this.name}}</h2>
{{/if}}
{{/each}}
但它不起作用。我也找不到任何有关执行 if 语句的文档。我找到的最接近的是:
https://sendgrid.com/docs/ui/sending-email/using-handlebars/
它谈到“Basic If, Else, Else If”,这表明有一个更高级的版本,但我找不到它的文档......
有谁知道我做错了什么?
PS:我的例子只是为了这篇文章而简化了。