Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:33:48+00:00 2026-06-02T02:33:48+00:00

What I want is to loop the data from database and create the menu,

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:33:49+00:00Added an answer on June 2, 2026 at 2:33 am
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript" src="Scripts/jquery-1.7.1.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                var data = [{ 'ID': 1, 'Name': 'A', 'NumCat': [{ 'ID': 1, 'Name': 'a' }, { 'ID': 2, 'Name': 'b' }, { 'ID': 3, 'Name': 'c'}] }, { 'ID': 2, 'Name': 'B', 'NumCat': [{ 'ID': 1, 'Name': 's'}] }, { 'ID': 3, 'Name': 'C', 'NumCat': [{ 'ID': 8, 'Name': 'r' }, { 'ID': 9, 'Name': 'y'}] }, { 'ID': 4, 'Name': 'D', 'NumCat': []}];
    
                if (data.length > 0) {
                    $('#content').append('<ul id="navmenu-v"></ul>');
    
                    $.each(data, function (index, dataMenu) {
                        var stringBuilder = [];
                        stringBuilder.push('<li class="testList"><a href="javascript:void(0);" id="' + dataMenu.ID + '">' + dataMenu.Name + '</a>');
    
                        if (dataMenu.NumCat.length > 0) { //NumCat is the amount of sub menu
                            stringBuilder.push('<ul>');
                            $.each(dataMenu.NumCat, function (i, dataSubmenu) {
                                stringBuilder.push('<li><a>' + dataSubmenu.Name + '</a></li>');
                            });
                            stringBuilder.push('</ul>');
                        }
    
                        stringBuilder.push('</li>');
    
                        $('#navmenu-v').append(stringBuilder.join(''));
                    });
                }
    
    
    
                // Or ( Above is for testing... )
    
    
                //            var url="/home/getmenulist"; // give u r url path here.
    
                //            $.getJSON(url, function (data) {
                //                if (data.length > 0) {
                //                    $('#content').append('<ul id="navmenu-v"></ul>');
    
                //                    $.each(data, function (index, dataMenu) {
                //                        var stringBuilder = [];
                //                        stringBuilder.push('<li class="testList"><a href="javascript:void(0);" id="' + dataMenu.ID + '">' + dataMenu.Name + '</a>');
    
                //                        if (dataMenu.NumCat.length > 0) { //NumCat is the amount of sub menu
                //                            stringBuilder.push('<ul>');
                //                            $.each(dataMenu.NumCat, function (i, dataSubmenu) {
                //                                stringBuilder.push('<li><a>' + dataSubmenu.Name + '</a></li>');
                //                            });
                //                            stringBuilder.push('</ul>');
                //                        }
    
                //                        stringBuilder.push('</li>');
    
                //                        $('#navmenu-v').append(stringBuilder.join(''));
                //                    });
                //                }
                //            });
            });
        </script>
    </head>
    <body>
        <div id="content">
        </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data from database coming out in a loop. Each of these
When we get tabular data from the database and want to show on the
I am selecting data from database and in while loop, i want it store
i have two foreach loop to display some data, but i want to use
I use a form where i have listed the data from database like title,
I have problem with encoding data in Oracle database. I want to xor string
i wanted to create a forloop which will create a table from the data
I have a map. On this map I want to show live data collected
How can I make this array with data from a database? $array=array(a=>Apple,b=>Ball,c=>Cat); I have
I create a panel in wxpython, plus i have a database(MySQLdb), then i select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.