var tree = {
0: [1, 2, 3, 4],
1: [5, 6],
2: [7],
3: [8],
4: [9]
}
var itemText = ["", "Home", "Favorites", "Font size", "Search", "Child node 1", "Child node 2", "Child node 3", "Child node 4", "Child node 5"];
var obj = new AW.UI.Tree;
obj.setItemText(itemText);
obj.setViewCount(function(i){return tree[i] ? tree[i].length : 0});
obj.setViewIndices(function(i){return tree[i]});
document.write(obj);
obj.getItemTemplate(2).raiseEvent("onTreeSignClicked");
function addNode() {
tree[2][tree[2].length] = itemText.length;
itemText[itemText.length] = "abcd";
obj.setItemText(itemText);
alert(obj.getItemTemplate(2).getViewProperty("expanded"));
obj.getItemTemplate(2).raiseEvent("onTreeSignClicked");
alert(obj.getItemTemplate(2).getViewProperty("expanded"));
obj.getItemTemplate(2).raiseEvent("onTreeSignClicked");
alert(obj.getItemTemplate(2).getViewProperty("expanded"));
}
<html>
<head>
<script src="activewidgets/runtime/lib/aw.js"></script>
<link href="activewidgets/runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<script>
var tree = {
0: [1, 2, 3, 4],
1: [5, 6],
2: [7],
3: [8],
4: [9]
}
var itemText = ["", "Node 1", "Node 2", "Node 3", "Node 4", "Node 5", "Node 6", "Node 7", "Node 8", "Node 9"];
var obj = new AW.UI.Tree;
obj.setItemText(itemText);
obj.setViewCount(function(i){return tree[i] ? tree[i].length : 0});
obj.setViewIndices(function(i){return tree[i]});
obj.setSize(300, 400);
document.write(obj);
// obj.getItemTemplate(2).raiseEvent("onTreeSignClicked");
function addNode(nodeNum, text) {
var itemTextLength = itemText.length;
if (!tree[nodeNum]) {
tree[nodeNum] = [itemTextLength];
} else {
tree[nodeNum][tree[nodeNum].length] = itemTextLength;
}
itemText[itemTextLength] = text;
obj.setItemText(itemText);
// alert(obj.getItemTemplate(2).getViewProperty("expanded"));
obj.getItemTemplate(nodeNum).raiseEvent("onTreeSignClicked");
// alert(obj.getItemTemplate(2).getViewProperty("expanded"));
obj.getItemTemplate(nodeNum).raiseEvent("onTreeSignClicked");
// alert(obj.getItemTemplate(2).getViewProperty("expanded"));
return itemTextLength;
}
</script>
<BR><BR>
<a href="#" onClick="addNode(2,'abcd'); return false;">add abcd to node 2</a><BR>
<a href="#" onClick="addNode(5,'xyz'); return false;">add xyz to node 5</a><BR>
<a href="#" onClick="addNode(9,'pqrs'); return false;">add pqrs to node 9</a><BR>
<a href="#" onClick="addNode(0,'ijkl'); return false;">add ijkl to node 0</a><BR>
<a href="#" onClick="var n = addNode(0,'123'); n = addNode(n,'456'); n = addNode(n,'789'); return false;">add 123 to node 0, then 456 to this new node and then 789 to the newest node</a><BR>
</body>
</html>
This topic is archived.