Dynamically loading sub-trees into YUI Treeview
Posted
by user319399
on Stack Overflow
See other posts from Stack Overflow
or by user319399
Published on 2010-04-17T20:20:19Z
Indexed on
2010/04/17
20:23 UTC
Read the original article
Hit count: 515
When you create a YUI TreeView instance, you can pass in an object that represents an entire tree, and it will automatically build up the TextNodes for you. I'd like to send in a partial tree, such that the tree only goes, say, 2 levels deep, and anything deeper than that will invoke dynamic loading. I've got that much working.
Now for the interesting part.
In the dynamic loading callback I give to my tree instance, I want to again be able to just give YUI a big object representing more of the tree. I want to do something like this:
// data is a array of objects organized into a tree, with some nodes requiring dynamic loading when they are navigated to
tree = new YAHOO.widget.TreeView("treeDiv1", data);
tree.setDynamicLoad(loadDataForNode);
function loadDataForNode(node, onCompleteCallback)
{
if(node.children.length==0)
{
var subTree = {
"label":"Cars",
isLeaf:false,
children:[
{
"label":"Chevy",
isLeaf:true
},
{
"label":"Ford",
isLeaf:true
},
]
};
// doesn't work, even though it has the required "label" field
var tempNode = new YAHOO.widget.TextNode(subTree, node, true);
}
onCompleteCallback();
}
Is this possible? Or do I have to iterate over all the nodes in my subtree and construct individual TextNodes for each one? Thanks much...
© Stack Overflow or respective owner