助手:
Handlebars.registerHelper('eq', function (a, b, opts) {
if (a == b) {
return opts.fn(this);
} else {
return opts.inverse(this);
}
});
数据:
var context = {
contributions : {
{T: 1, FN: "a", LN: "b"},
{T: 8, FN: "c", LN: "d"}
}
}
</tr>
以下模板:
<tr>
<td>1:</td>
<td>
{{#each contributions}}
{{FN}} {{LN}},
{{/each}}
</td>
</tr>
显示:
<tr><td>1:</td><td>a b,c d,</td></tr>
以下模板:
<tr>
<td>1:</td>
<td>
{{#each contributions}}
{{#eq T 8}}
{{FN}} {{LN}},
{{/eq}}
{{/each}}
</td>
</tr>
显示:
<tr><td>1:</td><td>a b,</td></tr>
也就是说:
我也尝试
<tr>
<td>1:</td>
<td>
{{#each contributions}}
{{#eq T 8}}
{{../FN}} {{../LN}},
{{/eq}}
{{/each}}
</td>
</tr>
获取:
<tr><td>1:</td><td>,</td></tr>
问题是:我怎么能得到
<tr><td>1:</td><td>c d,</td></tr>
甚至
<tr><td>1:</td><td>c d</td></tr>