HandlebarsJS - 如何显示嵌套的JSON

时间:2014-04-29 14:59:15

标签: json backbone.js handlebars.js

我有这个Backbone App,我用HandlebarsJS显示我的data / json。

现在我的API返回嵌套的JSON数据:

{
  "Live": [
  {
  "artist_name": "some artist",
  "video_title": " some video title",
  "video_thumbnail": "some thumbnail"
  }
 ],
 "Others" : [
  {
  "artist_name": "some artist",
  "video_title": " some video title",
  "video_thumbnail": "some thumbnail"
  }
 ]
}

我试着做

{{#each Live}}
  <div>
    <img src="{{video_thumbnail}}">
    <h2>{{video_title}}</h2>
    <h2>{{artist_name}}</h2>
  </div>
{{/each}}

但这没效果......

任何知道该怎么做的人?提前谢谢......

1 个答案:

答案 0 :(得分:-1)

把手模板可以两种方式使用。 1.我们可以使用(.hbs)保存文件 2.第二种方法是我们需要script标签中的车把模板。在[jsfiddle] [1]中提供了同样的内容,我提供了链接,您可以检查下面的链接

import EducationItem from 'wherever/your/component/is';