html - Create nested list view from JSON -


i'm trying create nested listed view jquery. data in json file. looks this:

{     "fakultaeten": [         {             "id": "1",             "name": "carl-friedrich gauß",             "institut": [                 "mathematik",                 "informatik"             ]         },         {             "id": "2",             "name": "lebenswissenschaften",             "institut": [                 "biologie/biotechnologie",                 "chemie/lebensmittelchemie"             ]         },         {             "id": "3",             "name": "architektur, bauingenieurwesen und umweltwissenschaften",             "institut": [                 "department architektur",                 "department bauingenieurwesen und umweltwissenschaften"             ]         },         {             "id": "4",             "name": "maschinenbau",             "institut": [                 "test"             ]         },         {             "id": "5",             "name": "elektrotechnik, informationstechnik, physik",             "institut": [                 "institut für datentechnik und kommunikationsnetze",                 "institut für elektrische maschinen, antriebe und bahnen"             ]         },         {             "id": "6",             "name": "geistes- und erziehungswissenschaften",             "institut": [                 "test"             ]         }     ] } 

i'm calling data this:

<script type="text/javascript" charset="utf-8">     $.getjson("fakultaeten.js",function(data)         {         $.each(data.fakultaeten, function(key,value)             {                 $.each(value.institut, function(key1,value1)                 {                     //console.log(value1)                 }              );             }         );         return false;          }     ); </script> 

now i'm little confused how display data in html code.

<div data-role="content">     <h3>institut für nachrichtentechnik</h3>     <ul id="tasklist" data-role="listview"></ul> </div> 

i know it's basic problem, other questions , tutorials found confusing me.

i want nested list in demo: http://jquerymobile.com/demos/1.2.1/docs/lists/lists-nested.html#&ui-page=2-4

it's simple: put list value inside list id tasklist:

<script type="text/javascript" charset="utf-8">         $.getjson("fakultaeten.js",function(data)         {         var list = $('#tasklist');         $.each(data.fakultaeten, function(key,value)             {                 var mother = "<li>"+value.name+"<ul>";                 $.each(value.institut, function(key1,value1)                 {                     var son="<li>"+value1+"</li>";                     mother+=son;                 }               );                 mother+="</ul></li>";                 list.append(mother);               }                         );         list.listview("refresh");         return false;          }     );     </script> 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -