如何通过把手渲染基于索引的JSON数据?

时间:2015-10-27 06:03:57

标签: arrays json handlebars.js

我有以下格式的JSON结构:

{
    "properties": {
        "title": "Title",
        "carouselName": {
            "id": [
                "carousel-1",
                "carousel-2",
                "carousel-3"
            ],
            "carouselImage": [
                "images/carousel-1.jpg",
                "images/carousel-2.jpg",
                "images/carousel-3.jpg"
            ],
            "carouselSubTitle": [
                "Sub Title 1",
                "Sub Title 2",
                "Sub Title 3"
            ],
            "breadText": [
                "Bread Text 1",
                "Bread Text 2",
                "Bread Text 3"
            ],
            "productUrl": [
                "#",
                "#",
                "#"
            ]
        }
    }
}

是否有用于渲染此类数据的内置手柄助手?提前谢谢!

1 个答案:

答案 0 :(得分:0)

没有内置的助手来实现同样的目标。但是,您可以使用内置的每个帮助程序来呈现相同的内容。例如,如下:

<div class="entry">
  <h1>{{properties.title}}</h1>
  <div class="body">
    {{#each properties.carouselName}}
      {{#each this}}
        <h5>{{this}}</h5>
      {{/each}}
    {{/each}}
  </div>
</div>