I took Yahoo's dynamic tree example and started making changes to
statically simulate what calling the database. All data is in Arrays.
The buildTree method gets the first Array loaded up as the root. All
good.
Now, I want to take the node the user clicks (call db with that id)
then load up that parent node with an array of it's children.
I can't seem to figure out the next steps:
1.) How do I get a handle on the node the user clicked?
2.)When I have the array of children, I'm looping through, how do I
assign them to their parent? This loop will only be for one parent at
a time.
Thanks everyone, couldn't do it without these groups sharing knowledge!
Here is my current code:
/*create namespace for examples:*/
YAHOO.namespace("example");
/* Using Crockford's "Module Pattern": */
YAHOO.example.treeExample = function() {
function buildTree() {
//create a new tree:
tree = new YAHOO.widget.TreeView("treeContainer");
//turn dynamic loading on for entire tree:
tree.setDynamicLoad(loadNodeData, currentIconMode);
//get root node for tree:
var root = tree.getRoot();
//create dummy data for root
var mycars = new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"
mycars[3] = "Ferrari"
mycars[4] = "Yugo"
mycars[5] = "Bentley"
for (i=0;i<mycars.length;i++)
{
new YAHOO.widget.TextNode(mycars[i], root, false);
}
tree.draw();
}
function loadNodeData(node, fnLoadComplete) {
//dummy data for bmw parent
var bmws = ["3 series","m series","5 series","7 series","6 series"];
var children = bmws;
//loop through children array and need to load up the bmw parent.
How to do this???
for (var i=0; i<children.length; i++) {
thisModel = children[i];
var newNode = new YAHOO.widget.TextNode(thisModel, node, false);
}
fnLoadComplete();
}
YAHOO.util.Event.addListener(window, "load",
YAHOO.example.treeExample.init, YAHOO.example.treeExample,true)