jquery - Push Json filtered key values to nested ul with Javascript -


i need pushing values filtered json, need generate nested ul list, can not modify json format @ point, check console.log see values create list, @ point can't figure how complete 'for loop' render html markup needed, appreciated, jsfiddle http://jsfiddle.net/43jh9hzz/, , if check console log see values.

this js:

                var json='';             var property_set = new set();             function iterate(obj, stack)  {                  json="<ul>";                  (var property in obj)  {                     if (obj.hasownproperty(property))  {                         if (typeof obj[property] == "object") {                             iterate(obj[property], stack + '.' + property);                         }                          else {                             // console.log(property);                             property_set.add(property);                             json+="<li>";                             if(typeof obj[property] !== "number") {                             json+="<li>"+obj[property]+"</li>";                             console.log(obj[property]);                             }                         }                     } json += "</li>";                 }             }              var listel = document.getelementbyid('output');             iterate(jsonobj) 

and json format:

                var jsonobj =              {                 "level_1": [                 {                     "level_1_name": "ciscosingaporeebc",                     "level_2": [                     {                         "level_2_name": "khoo tech puat",                         "level_2_id": 2222,                         "level_3": [                         {                             "name": "boon leong ong",                             "id": 6919                         },                         {                             "name": "kiat ho",                             "id": 6917                         },                         {                             "name": "overall experience",                             "id": 6918                         }                         ]                     }                     ]                 },                 {                     "level_1_name": "ciscolondonebc",                     "level_2": [                     {                         "level_2_name": "bernard mathews ltd.",                         "level_2_id": 2367,                         "level_3": [                         {                             "name": "barry pascolutti",                             "id": 7193                         },                         {                             "name": "kathrine eilersten",                             "id": 7194                         },                         {                             "name": "martin rowley",                             "id": 7189                         }                         ]                     },                     {                         "level_2_name": "fnhw day 1",                         "level_2_id": 5678,                         "level_3": [                         {                             "name": "jurgen gosch",                             "id": 7834                         },                         {                             "name": "overall experience",                             "id": 7835                         }                         ]                     },                     {                         "level_2_name": "groupe steria day 1",                         "level_2_id": 2789,                         "level_3": [                         {                             "name": "adam philpott",                             "id": 7919                         },                         {                             "name": "pranav kumar",                             "id": 7921                         },                         {                             "name": "steve simlo",                             "id": 7928                         }                         ]                     }                     ]                 }                 ]             }; enter code here 

i'm not sure if interpretting request correctly, think want: http://jsfiddle.net/mooreinteractive/43jh9hzz/1/

basically, calling iterate function run, that's it. function needs return value generates.

i've added end of function, after loop completes:

return json; 

do function returns value generated, there other issues too. when recursively call iterate function again inside iterate function, want add returns current json string housing of returned value.

so on line changed from:

iterate(obj[property], stack + '.' + property); 

to

json += iterate(obj[property], stack + '.' + property); 

now other value come inside main list creating in first run of function. ok that's pretty close, 1 more small thing. think when added additional surrounding li, wanted ul. changed uls , think result ul/li list representing text parts of json object.

again, may not after, think main take away using function return value, not generate it, nothing it.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -