tags:

views:

129

answers:

0

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...