22

寻找一种方法来实现这一点:

{{#each someArray}}
  {{../otherObject.[this]}}
{{/each}}

如何评估 的值,this然后将其作为我的对象的键引用otherObject

4

2 回答 2

19

通过查找:https ://handlebarsjs.com/guide/builtin-helpers.html#lookup

{{#each someArray}}
  {{lookup ../otherObject this}}
{{/each}}
于 2016-01-21T06:54:17.407 回答
5

使用助手的一种可能解决方案:

/*
{{#each someArrayOfKeys}}
  {{#withItem ../otherObject key=this}}
    {{this}}
  {{/withItem}}
{{/each}}
*/

Handlebars.registerHelper('withItem', function(object, options) {
    return options.fn(object[options.hash.key]);
});
于 2014-04-25T22:14:18.250 回答