TonyLock Posted October 7, 2010 Share Posted October 7, 2010 Can some one help me make the following JSON data: { "main": { "label":"Main", "url":"#main" }, "project": { "label":"Project", "url":"#project" }, "settings": { "label":"Settings", "url":"#settings", "subnav":[ { "label":"Privacy", "url":"#privacy" }, { "label":"Security", "url":"#security" }, { "label":"Advanced", "url":"#advanced" } ] } } into the following bullets list using JS? Assuming you don't know what the first nodes are call labeled (e.g. "main", "project" <- these will be dynamically generated): Main (#main) Project (#project) Settings (#settings) Privacy (#privacy) Security (#security) Advanced (#advanced) Thanks Link to comment Share on other sites More sharing options...
0 TonyLock Posted October 8, 2010 Author Share Posted October 8, 2010 Please can someone help me? This has been driving me insane today. Link to comment Share on other sites More sharing options...
0 TonyLock Posted October 8, 2010 Author Share Posted October 8, 2010 Anyone have any thoughts on this? Link to comment Share on other sites More sharing options...
0 RoomKid Posted October 9, 2010 Share Posted October 9, 2010 I was going to post the other day but I was too busy. Anyway, here's a working example: http://content.manmohanjit.com/uploads/neowin/tonylock/ Get the JS here: http://content.manmohanjit.com/uploads/neowin/tonylock/js.txt Just change data.json to the json file and #divToAddTo to the location. Link to comment Share on other sites More sharing options...
0 TonyLock Posted October 9, 2010 Author Share Posted October 9, 2010 Cool, thanks. Is it possible to put the JSON data in to a variable like the following and still use your code? var ListData = { "main": { "label":"Main", "url":"#main" }, "project": { "label":"Project", "url":"#project" }, "settings": { "label":"Settings", "url":"#settings", "subnav":[ { "label":"Privacy", "url":"#privacy" }, { "label":"Security", "url":"#security" }, { "label":"Advanced", "url":"#advanced" } ] } }; Link to comment Share on other sites More sharing options...
0 RoomKid Posted October 9, 2010 Share Posted October 9, 2010 That my man is not JSON anymore, it's an object. Anyway ya you can. It works both ways. Have a look here, http://content.manmohanjit.com/uploads/neowin/tonylock/js2.txt I'm putting the code in a text file over at my site because Neowin doesn't format the code that well ;) Link to comment Share on other sites More sharing options...
0 TonyLock Posted October 10, 2010 Author Share Posted October 10, 2010 That's cool! THanks so much iHaz. :-) I have one more question for you. Using Javascript, how could new top-level entries be added dynamically insert after the "settings" entry in to ListData variable? In the following example, I'm adding ,"JOSN_IS_COOL": {"label": "Jason siad hello", "url": "#JSON"} { "main": { "label": "Main", "url": "#main" }, "project": { "label": "Project", "url": "#project" }, "settings": { "label": "Settings", "url": "#settings", "subnav": [{ "label": "Privacy", "url": "#privacy" }, { "label": "Security", "url": "#security" }, { "label": "Advanced", "url": "#advanced" }] }, "JOSN_IS_COOL": { "label": "Jason siad hello", "url": "#JSON" }, }; Link to comment Share on other sites More sharing options...
Question
TonyLock
Can some one help me make the following JSON data:
{ "main": { "label":"Main", "url":"#main" }, "project": { "label":"Project", "url":"#project" }, "settings": { "label":"Settings", "url":"#settings", "subnav":[ { "label":"Privacy", "url":"#privacy" }, { "label":"Security", "url":"#security" }, { "label":"Advanced", "url":"#advanced" } ] } }into the following bullets list using JS? Assuming you don't know what the first nodes are call labeled (e.g. "main", "project" <- these will be dynamically generated):
Thanks
Link to comment
Share on other sites
6 answers to this question
Recommended Posts