Skip to main content

Yahoo Tree Dynamic load

1 reply [Last post]
csmith_oopscope
Offline
Joined: 2004-04-05

Here is a modification to the jMaki/Yahoo tree to utilize the dynamic load capability built into the YUI component - works great!:

Substitute the original lines (36-39) of component.js:

} else if (typeof wargs.value == 'object') {
buildTree(wargs.value.root);
}

With:

} else if (typeof wargs.value == 'object') {
var dynamicLoadCallback = wargs.value.root.dynamicLoadCallback;
if (typeof dynamicLoadCallback != 'undefined') {
// Load the tree dynamically
this.tree.setDynamicLoad(dynamicLoadCallback);
}
buildTree(wargs.value.root);
}

Add the callback function to the constructor tag:

And the call back function (Product tree example):

function loadDataForNode(node, onCompleteCallback) {
var id = node.label;
switch (id) {
case 'Navigation Tree':
// Insert the root nodes
var tmpNode = new YAHOO.widget.MenuNode('Products', node, false);
tmpNode = new YAHOO.widget.MenuNode('Services', node, false);
onCompleteCallback();
break;
case "Products":
// Add the
getProducts( function(products) {
updateNode(node, products,false);
onCompleteCallback();
});
break;
case "Services":
// Load the services
break;
default:
var parentId = node.parent.label;
debug("Parent=" + parentId);
if (typeof parentId != 'undefined' ) {
// Check for 3rd level - not very reliable
if (parentId == 'Products' || parentId == 'Services') {
// Get the products
getProductsForLine(id, function(products) {
updateNode(node, products,true);
onCompleteCallback();
// Notify the change listeners
jmaki.publish("/oopscope/navigation", id);
});
} else {
// Load the product
productName = node.label;
jmaki.publish("/oopscope/navigation", productName);
onCompleteCallback();
}
}
break;
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31

Hi Csmith,

Thank you for the suggestion.

Could you write me at gregory dot murray at sun dot com? We will need to get a contributor license agreement to add code and I can work with you on that.

-Greg