I have a Json with this structure:
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",
}
}
and the js is as follow:
var source = $("#entry-template").html();
var template = Handlebars.compile(source);
var html = template(data);
$('#Content').html(html);
I need to get access to data.h.categoryTitle and data.j.categoryTitle as first iteration then data.h.results.Title and data.j.results[0].Title and data.j.results[1].Title as nested iteration, this is my template:
<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>
Its not showing anything :-| how can I do this with Handlebars?
Many Thanks!