【问题标题】:Access a JSON value while iterating over array in HandleBar jsp在 HandleBar jsp 中迭代数组时访问 JSON 值
【发布时间】:2018-03-02 07:08:14
【问题描述】:

我有一个具有以下值的 json(示例)。

[  
   {  
      "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}}

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

【问题讨论】:

    标签: jsp handlebars.js aem


    【解决方案1】:

    您可以使用{{@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

    【讨论】:

      猜你喜欢
      • 2017-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-05
      • 2019-05-01
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多