How to display JSON nested array in ember templates using handlebars?


#1

How to display JSON nested array in ember templates using handlebars ?

My json api from server is :-

{
taxonomies:[
{
id:2,
name:“Brand”,
root:{
id:2, name:“Brand”, pretty_name:“Brand”, permalink:“brand”, parent_id:null, taxonomy_id:2, taxons:[
{
id:8, name:“Ruby”, pretty_name:“Brand -> Ruby”, permalink:“brand/ruby”, parent_id:2, taxonomy_id:2 }, {
id:9, name:“Apache”, pretty_name:“Brand -> Apache”, permalink:“brand/apache”, parent_id:2, taxonomy_id:2 }, {
id:10, name:“Spree”, pretty_name:“Brand -> Spree”, permalink:“brand/spree”, parent_id:2, taxonomy_id:2 }, {
id:11, name:“Rails”, pretty_name:“Brand -> Rails”, permalink:“brand/rails”, parent_id:2, taxonomy_id:2 } ] } } ] }

and i want to display taxons -> name in my handlebars template

{{#each}} only show bullets but not the data

I dont know how to loop over the array. {{taxonomy.root.taxons.firstObject.pretty_name}} displays the name but only the first object of each taxon and not all of them

    {{#each taxonomy in controller}} {{#each}}
  • {{taxonomy.root.taxons.pretty_name}}
  • {{/each}} {{/each}}

How can I get the data?


#2

App.js

App.DeepRoute = Ember.Route.extend({
model :function(){
	var yourJson= {
			taxonomies:.......
                 };
	return yourJson.taxonomies[0].root.taxons;
}

});

template html

<script type="text/x-handlebars" id="deep">
{{#each}}
{{pretty_name}}</br>
{{/each}}
</script>

I hope you have a pretty code ;