访问对象值寻找一种方式来获得实现这一点:Handlebars.js - 一个可变密钥
{{#each someArray}}
{{../otherObject.[this]}}
{{/each}}
如何评估的this
值,然后引用它作为重点,以我的对象otherObject
?与助手
访问对象值寻找一种方式来获得实现这一点:Handlebars.js - 一个可变密钥
{{#each someArray}}
{{../otherObject.[this]}}
{{/each}}
如何评估的this
值,然后引用它作为重点,以我的对象otherObject
?与助手
一个可能的解决方案:
/*
{{#each someArrayOfKeys}}
{{#withItem ../otherObject key=this}}
{{this}}
{{/withItem}}
{{/each}}
*/
Handlebars.registerHelper('withItem', function(object, options) {
return options.fn(object[options.hash.key]);
});
随着查找:http://handlebarsjs.com/builtin_helpers.html#lookup
{{#each someArray}}
{{lookup ../otherObject this}}
{{/each}}
就是最好的答案 – zavr
正如其他答案已经指出的那样,你可能想lookup
。
但是,如果您使用EmberJS(在撰写本文时为2.12.0),则需要get
。
阅读侧边栏中的相关问题并进行一些搜索,我确定这是一个重复的问题。 –
我有,搜索了2天。也许我只是在使用谷歌搜索。 –
[This side from the sidebar](http://stackoverflow.com/questions/18168924/how-to-get-an-array-value-at-index-using-handlebars-js?rq=1)约为90解决方案的百分比。基本上,您必须编写自己的帮助器,将诸如'{{value_at obj key}}'之类的东西转换为JavaScript'obj [key]'。 –