var treeData = [
{title: “item1 with key and tooltip”, tooltip: “Look, a tool tip!” },
{title: “item2: selected on init”, select: true },
{title: “Folder”, isFolder: true, key: “id3”,
children: [
{title: “Sub-item 3.1”,
children: [
{title: “Sub-item 3.1.1”, key: “id3.1.1” },
{title: “Sub-item 3.1.2”, key: “id3.1.2” }
]
},
{title: “Sub-item 3.2”,
children: [
{title: “Sub-item 3.2.1”, key: “id3.2.1” },
{title: “Sub-item 3.2.2”, key: “id3.2.2” }
]
}
]
},
{title: “Document with some children (expanded on init)”, key: “id4”, expand: true,
children: [
{title: “Sub-item 4.1 (active on init)”, activate: true,
children: [
{title: “Sub-item 4.1.1”, key: “id4.1.1” },
{title: “Sub-item 4.1.2”, key: “id4.1.2” }
]
},
{title: “Sub-item 4.2 (selected on init)”, select: true,
children: [
{title: “Sub-item 4.2.1”, key: “id4.2.1” },
{title: “Sub-item 4.2.2”, key: “id4.2.2” }
]
},
{title: “Sub-item 4.3 (hideCheckbox)” },
{title: “Sub-item 4.4 (unselectable)” }
]
}
];
var tryTree = [{}];
tryTree[0] = {};
tryTree[0].title = “item1 with key and tooltip”;
tryTree[0].tooltip = “Look, a tool tip!”;
tryTree[1] = {};
tryTree[1].title = “item2: selected on init”;
tryTree[1].select = true;
tryTree[2] = {};
tryTree[2].title = “Folder”;
tryTree[2].isFolder = true;
tryTree[2].key = “id3”;
tryTree[2].children = [{}];
tryTree[2].children[0] = {};
tryTree[2].children[0].title = “Sub-item 3.1”;
tryTree[2].children[0].children = [{}];
tryTree[2].children[0].children[0] = {};
tryTree[2].children[0].children[0].title = “Sub-item 3.1.1”;
tryTree[2].children[0].children[0].key = “id3.1.1”;
tryTree[2].children[0].children[1] = {};
tryTree[2].children[0].children[1].title = “Sub-item 3.1.2”;
tryTree[2].children[0].children[1].key = “id3.1.2”;
tryTree[2].children[1] = {};
tryTree[2].children[1].title = “Sub-item 3.2”;
tryTree[2].children[1].children = [{}];
tryTree[2].children[1].children[0] = {};
tryTree[2].children[1].children[0].title = “Sub-item 3.2.1”;
tryTree[2].children[1].children[0].key = “id3.2.1”;
tryTree[2].children[1].children[1] = {};
tryTree[2].children[1].children[1].title = “Sub-item 3.2.2”;
tryTree[2].children[1].children[1].key = “id3.2.2”;
tryTree[3] = {};
tryTree[3].title = “Document with some children (expanded on init)”;
tryTree[3].expand = true;
tryTree[3].key = “id3”;
tryTree[3].children = [{}];
tryTree[3].children[0] = {};
tryTree[3].children[0].title = “Sub-item 4.1 (active on init)”;
tryTree[3].children[0].activate = true;
tryTree[3].children[0].children = [{}];
tryTree[3].children[0].children[0] = {};
tryTree[3].children[0].children[0].title = “Sub-item 4.1.1”;
tryTree[3].children[0].children[0].key = “id4.1.1”;
tryTree[3].children[0].children[1] = {};
tryTree[3].children[0].children[1].title = “Sub-item 4.1.2”;
tryTree[3].children[0].children[1].key = “id4.1.2”;
tryTree[3].children[1] = {};
tryTree[3].children[1].title = “Sub-item 4.2 (selected on init)”;
tryTree[3].children[1].select = true;
tryTree[3].children[1].children = [{}];
tryTree[3].children[1].children[0] = {};
tryTree[3].children[1].children[0].title = “Sub-item 4.2.1”;
tryTree[3].children[1].children[0].key = “id4.2.1”;
tryTree[3].children[1].children[1] = {};
tryTree[3].children[1].children[1].title = “Sub-item 4.2.2”;
tryTree[3].children[1].children[1].key = “id4.2.2”;
tryTree[3].children[2] = {};
tryTree[3].children[2].title = “Sub-item 4.3 (hideCheckbox)”;
tryTree[3].children[3] = {};
tryTree[3].children[3].title = “Sub-item 4.4 (unselectable)”;
Tested with
//called with every property and it’s value
function process(key,value) {
document.write(key + ” : “+value+'<br/>’);
}
function traverse(o,func) {
for (i in o) {
func.apply(this,[i,o[i]]);
if (typeof(o[i])==”object”) {
//going on step down in the object tree!!
traverse(o[i],func);
}
}
}
//that’s all… no magic, no bloated framework
document.write(‘<br/><br/><br/><br/><br/><br/><br/><br/><table><tr><td>’);
traverse(treeData,process);
document.write(‘</td><td>’);
traverse(tryTree,process);
document.write(‘</td></tr></table>’);