What I want is to loop the data from database and create the menu, if each content of the menu
have the sub menu, then it will show the sub menu as :
<ul>
<li>test1</li>
<li>test2</li>
<li>test3
<ul>
<li>sub menu1</li>
<li>sub menu2</li>
</ul>
</li>
</ul>
I create the menu with the Jquery as below :
$(document).ready(function () {
$.getJSON(url, function (data) {
$.each(data, function (index, dataOption) {
$("#navmenu-v").append("<li id='testList'>
<a href='javascript:void(0);' id='" + dataOption.ID + "'>" +
dataOption.Name + "</a>");
if (dataOption.NumCat > 0) { //NumCat is the amount of sub menu
$("#testList").append("<ul><li><a>Testing cate</a></li></ul>");
}
$("#navmenu-v").append("</li>");
});
});
});
<div id="content">
<ul id='navmenu-v'>
</ul>
</div>
But the “Testing cate” shows only in the first list of the menu.
Could anyone tell me how to do that please. Thanks so much.
1 Answer