I have the following kind of array.
[{
tag:'a',
href:"#",
title:"test",
children:[{
tag:"div",
id:"nested-image",
children:[{
tag:"img",
src:"image.jpg"
}]
}]
}]
}]
For rendering it I am using Underscore templates. I have used text plugin for loading templates
I am using following function for rendering.
compiledTpl: function(tpl, data) {
var data = data || {};
var compiled = _.template(tpl);
return compiled(data);
},
From one of the templates I'm calling following function like this:
Inside the template I am iterating data object:
<%_.each(data),function(d){%>
<p>d.a</p>
<p>d.b</p>
<%if(d.children.length>0){%>
//call same template itself
<%= _.compiledTpl(tpl1,{'data':data} ) %>//not sure how to do that
<%}%>
<%}%>
If the function calls itself and everything is fine then it will not iterate through all the children of first level as in only one hierarchy will be there. It will not iterate through all children. I want to achieve something like this http://techdive.in/java/recursive-templates-underscore-js