寻找实现此目的的方法:
{{#each someArray}}
{{../otherObject.[this]}}
{{/each}}
如何评估this
的值,然后将其作为对象otherObject
的键引用?
答案 0 :(得分:16)
使用查询:http://handlebarsjs.com/builtin_helpers.html#lookup
{{#each someArray}}
{{lookup ../otherObject this}}
{{/each}}
答案 1 :(得分:5)
帮助者的一种可能解决方案:
/*
{{#each someArrayOfKeys}}
{{#withItem ../otherObject key=this}}
{{this}}
{{/withItem}}
{{/each}}
*/
Handlebars.registerHelper('withItem', function(object, options) {
return options.fn(object[options.hash.key]);
});