寻找一种方法来实现这一点:
{{#each someArray}}
{{../otherObject.[this]}}
{{/each}}
如何评估 的值,this
然后将其作为我的对象的键引用otherObject
?
寻找一种方法来实现这一点:
{{#each someArray}}
{{../otherObject.[this]}}
{{/each}}
如何评估 的值,this
然后将其作为我的对象的键引用otherObject
?
通过查找:https ://handlebarsjs.com/guide/builtin-helpers.html#lookup
{{#each someArray}}
{{lookup ../otherObject this}}
{{/each}}
使用助手的一种可能解决方案:
/*
{{#each someArrayOfKeys}}
{{#withItem ../otherObject key=this}}
{{this}}
{{/withItem}}
{{/each}}
*/
Handlebars.registerHelper('withItem', function(object, options) {
return options.fn(object[options.hash.key]);
});