Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i do not have enough knowledge of java script. i want to create a menu like this
HTML
<ul> for a particular grand parentname from code 2
 <li></li> contain parentname  
 <li>contain parentname 
   <ul>conatin node name regarding parentname from code1
     <li></li>
     <li></li>
   </ul>
 </li>
 <li>contain parentname 
    <ul>conatin node name regarding parentname from code1
      <li></li>
      <li></li>
    </ul>
 </li>
</ul>

the json files i have are
1.
XML
{"Table":
    [
       {"NodeName":"Casio EF-562D-1A Watch","NodeLevel":3,"ParentName":"Casio Watch","ParentId":2,"domain":124},
       {"NodeName":"Casio Watch (model: MTP-1170N-9A) ","NodeLevel":3,"ParentName":"Casio Watch","ParentId":2,"domain":124},
       {"NodeName":"Casio Watch (G-SHOCK GA-100-1A4) ","NodeLevel":3,"ParentName":"Casio Watch","ParentId":2,"domain":124},
       {"NodeName":"Amazing Big Bag With Chivas Signature Exclusive on Dutyfree","NodeLevel":3,"ParentName":"Chivas Bags","ParentId":2,"domain":124},
       {"NodeName":"Camel Silver/ Super Light Box Cigarette","NodeLevel":3,"ParentName":"Camel","ParentId":2,"domain":124},
       {"NodeName":"10 Cartons of Camel Silver/ Super Light Box Cigarette","NodeLevel":3,"ParentName":"Camel","ParentId":2,"domain":124}
    ]
 }

2.
XML
{"Table":[
     {"parent_name":"Casio Watch","id":2,"grandpname":"Accessories","gid":1,"domain":124},
     {"parent_name":"Chivas Bags","id":2,"grandpname":"Accessories","gid":1,"domain":124},
     {"parent_name":"Camel","id":2,"grandpname":"Cigarettes","gid":1,"domain":124}]}
Posted

1 solution

Your JSON will be very difficult to parse into HTML elements. My advice would be (if possible) to change your JSON to something like this
JavaScript
{
  "categories":["Accessories","Cigarettes"],
  "subCategories":[
             {"name":"Casio Watch", "category":"Accessories"},
             {"name":"Chivas Bags", "category":"Accessories"},
             {"name":"Camel", "category":"Cigarettes"}],
  "items":[
             {"name":"Casio EF-562D-1A Watch","subcategory":"Casio Watch"},
              {"name":"Camel Silver/ Super Light Box Cigarette","subcategory":"Camel"}]
}

JSON like this can very easily be parsed into something like this
HTML
<ul id="menu">
    <li>Accessories
        <ul>
           <li>Casio Watch
              <ul>
                 <li>Casio EF-562D-1A Watch</li>
              </ul>
           </li>
           <li>Chivas Bags</li>
        </ul>
    </li>
    <li>Cigarettes
        <ul>
           <li>Camel
               <ul>
                  <li>Camel Silver/ Super Light Box Cigarette</li>
               </ul>
           </li>
        </ul>
    </li>
</ul>

If you can change your JSON definition then reply to my post and I will help you write the code to get the JSON files and parse then to markup.
 
Share this answer
 
Comments
rajat321 19-May-14 2:39am    
yes i can change my json definition .. in last i must be able to generate a menu with submenus as u have shown

also suggest me the code to change json as u have shown because the json i've shown in question is being generated from two different tables of database

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900