【发布时间】:2019-01-04 13:36:10
【问题描述】:
我正在尝试使用每个嵌套显示照片的 cmets,但我无法让它工作:
照片:{id、描述、所有者、链接}的数组
cmets: array of {id, commentText, photoTarget} //photoTraget 是照片的id
index.js:
res.render('wall', { title: "Baker's Wall", photos, comments });
wall.hbs:
{{#each photos}}
{{@index}}: {{this}}
{{#each ../comments}}
{{#if_eq photoTarget @../index.id}}
<div class="titleR1">{{this.text}}</div>
{{/if_eq}}
{{/each}}
{{/each}}
app.js:
hbs.registerHelper('if_eq', function(a, b, opts) {
if(a == b)
return opts.fn(this);
else
return opts.inverse(this);
});
编辑
【问题讨论】:
-
您能否重新格式化
photos和comments数组,以便我们看到它们的样子?当前输出是多少? -
@Rastalamm 我添加了一些截图。我没有得到任何输出,不满足 if_eq 的条件
标签: javascript express handlebars.js helper