在HandleBar jsp中迭代数组时访问JSON值

问题描述 投票:1回答:1

我有一个带有以下值的json(Sample)。

[  
   {  
      "sectionTitle":"LATEST NEWS",
      "language":"ENGLISH",
      "sectionLink":"/content/ml/sample.html",
      "newTab":"",
      "ViewType":"slrr",
      "bgColor":"red",
      "fontColor":"white",
      "logo":"",
      "articleNewTab":"true",
      "Results":[ 
        {  "title":"sample title",
          "description":"sample desc"},
        {
         "title":"sample title1",
          "description":"sample desc1"}
    ],
      "morelinkJson":{  
         "moreLink":"/content/mm/ml/news/just-in.html",
         "moreLinkNewTab":false
      }
   }
]

在这里,我通过迭代使用显示“结果”

{{#each this.0.Results}}

在这个循环中我想访问values- sectionTitle,language ...等。但我不能。我在这里使用车把jsp。

jsp handlebars.js aem cq5
1个回答
0
投票

您可以使用{{@root.0.someThing}}模式访问它们。

{{#each this.0.Results}}
      <div class="entry">
        <h1>{{title}}{{@root.0.sectionTitle}}</h1> 
        <div class="body">
          {{@root.0.language}}
          {{description}}
        </div>
      </div>
{{/each}}

Plunker

© www.soinside.com 2019 - 2024. All rights reserved.