把手-遍历JSON数组

时间:2019-11-11 03:42:02

标签: handlebars.js

我正在尝试使用手柄条形码遍历JSON数组,如下所示。

JSON数组:

[{"email":"zzz@g.com","repo":"https://github.com"},{"email":"xxx@g.com","repo":"https://github.com"},{"email":"yyy@g.com","repo":"https://github.com"}]

处理条形码:

{{#each ["abc"].[json]}}
       EMAIL:{{["abc"].[json].[@index].[email]}}
       REPO:{{["abc"].[json].[@index].[repo]}}
       {{#if @last }}
           Last entry!
        {{/if}}
    {{/each}}

其中[“ abc”]。[json]。[0 ... 100] .email / repo是上一进程的输出Json数组。使用上面的代码,我没有得到所需的结果,并且输出为空字符串,非常感谢您的帮助。

必需的输出:

EMAIL:zzz@g.com
REPO:https://github.com
EMAIL:xxx@g.com
REPO:https://github.com

1 个答案:

答案 0 :(得分:1)

#each帮助器中,上下文切换到当前元素,类似于JS中的forEach方法:

{{#each ["abc"].[json]}}
   EMAIL:{{email}}
   REPO:{{repo}}
   {{#if @last }}
       Last entry!
    {{/if}}
{{/each}}
相关问题