I\'m trying to create a nested UL from JSON. I am able to loop through and grab the data from the object, but I am having trouble building the nested UL. I figure the \'.app
You can use a recursive function for appending submenus.
This is a simple solution for three sublevels or more
function appendMeu(parent, menu, level) {
for(var i = 0;i < menu.length; i ++) {
var submenu = parent.append('- ' + menu[i].title + '
')
.find("li:last");
if(menu[i].menu != undefined && menu[i].menu.length > 0) {
submenu = submenu.append('').find("ul");
appendMeu(submenu, menu[i].menu, level + 1);
}
}
}
$(function() {
appendMeu($(".mainMenu"), menu, 0);
});