Jump to content
  • 0

Tree view


xaero
 Share

Question

Na primer u menya est takoy massiv:

var tree = ['Home',

'Products',

'JavaScript',

['Functions',

'Objects',

'Classes',

['DYNAPI',

'MyFrame',

'X-Objects'

],

'Variables'

],

'Current',

'Machines'

]

Ya xotel bi ego otobrajat kak tree view pomogite napisat funksiyu...

Ya sam poproboval no eto ogronicheno,

function TM(a)

{

for(i=0; i

{

if(typeof a=='object')

{

for(ii=0; ii

{

if(typeof a[ii]=='object')

{

for(iii=0; iii

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Как-нибудь так, наверно:

var tree = ['Home',
'Products',
'JavaScript',
['Functions',
'Objects',
'Classes',
['DYNAPI',
'MyFrame',
'X-Objects'
],
'Variables'
],
'Current',
'Machines'
];

function F(t) {
var html = '<ul>',
item;
for (var i = 0, len = t.length; i < len; i++) {
item = t[i];
if (typeof item == 'string') {
html += '<li>' + item + '</li>';
} else if (item instanceof Array) {
html = html.substring(0, html.lastIndexOf('</li>'));
html += F(item);
}
}
html += '</ul>';
return html;
}

onload = function () {
document.body.innerHTML += F(tree);
}

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy