I have a bit of code that loops through nested array (it can be unlimited in depth) and I am trying to generate a treelike structure from it.. of basically nested unordered lists..
Here is my fiddle http://jsfiddle.net/aj9TC/6/
I collect items names in a function like this:
function get_list( a ) {
for (var i = 0; i < a.length; i++) {
console.log( i + "---" + a[i].name );
$(".mod-list ul").append('<li>' + a[i].name + '</li>');
get_list( a[i].group );
}
}
get_list( mods.group );
My sample html is simple
<h4>Nested List</h4>
<div class="mod-list">
<ul class="list">
</ul>
</div>
I currently append all items as li in a single unordered list,, but I need to create nested unordered lists that reflect the array nesting accurately.
Can someone help me out with this please.
Thanks!