[英]Handlebars.js - Access object value with a variable key
尋找一種方法來實現這一點:
{{#each someArray}}
{{../otherObject.[this]}}
{{/each}}
如何評估值this
,然后引用它作為重點,以我的對象otherObject
?
使用查找: http : //handlebarsjs.com/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]);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.