我有一个global.json文件:
I have a global.json file:
{ "title": "problem", "dict": [ { "name": "A", "similar": [1, 2] }, { "name": "B", "similar": [0] }, { "name": "C", "similar": [1] }, ] },我希望将A的以下结果作为示例:
and I want the following result for A as an example:
A B C我尝试使用以下车把脚本:
I tried to use the following handlebars script:
{{#with global.dict.[0]}} {{name}} {{#each similar}} {{@root.global.dict.[this].name}} {{/each}} {{/with}}输出仅为A.但是,似乎this在这里不能识别为整数用作索引
The output is is just A. However, it seems this is not recognized as integer here to used as the index
推荐答案您将需要使用查找助手来查找 @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.
更多推荐
Handlebars.js:从循环中索引对global.json的访问
发布评论