且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Handlebars.js:从循环中索引对global.json的访问

更新时间:2023-01-08 15:50:31

您将需要使用查找助手来查找 @root.global.dict上的动态this索引.然后,您将不得不进行第二次查找以获取结果的name属性.另外,您可以使用 with 助手来为您提供范围为第一次查找的结果,如:

You will need to use the lookup helper to lookup the dynamic this index on @root.global.dict. You would then have to do a second lookup to get the name property of the result. Alternatively, you could use the with helper to give you a block scoped to the result of the first lookup, as in:

{{#each similar}}
    {{#with (lookup @root.global.dict this)}}
        {{name}}
    {{/with}}
{{/each}}

我创建了一个小提琴供您参考.

I have created a fiddle for your reference.