i'm writing a plugin in jquery to be a file manager i build my folder structure in php i call that php file using ajax and i return something like this
{"1":[],"css":{"admin":[],"tabs":{"skin1":{"images":[]},"skin10":{"images":[]},"skin11":{"images":[]},"skin12":{"images":[]},"skin2":[],"skin3":{"images":[]},"skin4":{"images":[]},"skin5":{"images":[]},"skin6":{"images":[]},"skin7":{"images":[]},"skin8":{"images":[]},"skin9":{"images":[]}}},"img":{"admin":[],"filemanager":[],"icons":[]},"js":{"libs":[]},"menu":{"img":[]},"walpappere":{"1":[]}}
how can i parse the info using jquery or javascript to do something like this
var mystring = ''
foreach key (would be 1,css etc)
mystring += key
if has children
mystring += key
for each children same as above until all structure is parsed
I would also look into using jQuery with jQuery tmpl and tmpl.plus. You could then create a recursive template to render. There is a bit of a learning curve but man does it really separate markup away from your logic ect. jQuery tmpl
If the recursion is done right, it could be as easy as calling:
This kind of workflow is great for really dynamic sites
$.isPlainObject
is from jQuery. If you don't want to use jQuery, it's equivalent to:{}.toString.call( obj[key] ) === '[object Object]'
Create a function which does that: http://jsfiddle.net/k5BTr/.