我有一个具有这种结构的 Json:
var data = {
"h": {
"results": {
"0": {
"title": "Do feral cats affect small animals?",
"authors": " Billie Theresa Lazenby, Billie Theresa Lazenby",
"url": "#",
"published": 2012,
"summary": ""
}
},
"categoryTitle": "Sydney eScholarship",
},
"j": {
"results": {
"0": {
"title": "Utagawa Kunisada II",
"description": "You can learn more ...",
"url": "#",
"thumb": "#",
"published": 2010
},
"1": {
"title": "Utagawa Kunisada II2",
"description": "You can learn more ...",
"url": "#",
"thumb": "#",
"published": 2012
}
},
"categoryTitle": "YouTube",
}
}
js如下:
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
var html = template(data);
$('#Content').html(html);
我需要访问 data.h.categoryTitle 和 data.j.categoryTitle 作为第一次迭代,然后是 data.h.results.Title 和 data.j.results[0].Title 和 data.j.results[1].Title作为嵌套迭代,这是我的模板:
<div id="content"> </div>
<script id="entry-template" type="text/x-handlebars-template">
{{#each data}}
<div class="searchResultItem col-sm-9 col-xs-12">
{{#each results}}
<a href="#" class="title">{{this.title}}</a>
{{/each}}
<span>{{this.categoryTitle}}</span>
</div>
{{/each}}
</script>
它没有显示任何东西:-| 我怎么能用把手做到这一点?
非常感谢!