Good evening! I solve the problem of forming a tree list.
There is for example such an array:
$mas = array ( "City" => array ( "a" => "New-York", "b" => "London", "c" => "Moscow" ), "Numbers" => array ( "element-1", "element-2", "element-3", "element-4", "element-5", "element-6" ), "Other" => array ( "one", 5 => "two", "three", 7=> array ("mas10", "mas15") ) );
After conversion to JSON-format, the array looks like this:
{ "City":{"a":"New-York","b":"London","c":"Moscow"}, "Numbers" ["element-1","element-2","element-3","element-4","element-5","element-6"], "Other":{"0":"one","5":"two","6":"three","7":["mas10","mas15"]} }
Through JSON, I pass it to the JS code, which has a function that lists the tags:
function Dump(d,l) { if (l == null) l = 1; var s = ''; if (typeof(d) == "object") { s += "<li><img src='../images/folder.gif' />"; for (var k in d) { s += "<ul>" + Dump(d[k],l+1)+"</ul>"; } s += "</li>"; } else { s += "<li><img src='../images/file.gif' />" + d + "</li>"; } return s; } str = Dump(data,1); $("#span2").html(str);
And the whole thing is formed in this form: http://www.imgup.ru/image-12jrx7161953.html
And I would like to make the headings of elements that are arrays in turn (such as "City" or "7") show their headings, and elements that simply store values do not show their headings (such as the key "a", "5" or simply values without a specified key as for example "element-3", "mas15", etc.). How to do it? I tried to print the values of k in a loop, but it displays all the keys, even if they are not arrays.