pradnesh.alve
13 Sep 2007, 5:54 AM
Hi,
I am trying to us the Tree component of the Ext JS. My basic requirement is that the tree should load the first level of nodes on the first load. On clicking the first level of nodes, there should be an AJAX call that loads the children of that node. Following is the code that I have written:
<script type="text/javascript">
var tree;
Ext.onReady(function()
{
// Creating a new tree loader.
var loader = new Ext.tree.TreeLoader({dataUrl:'get_parent_nodes.jsp'});
// Setting the URL for retrieving the child elements.
loader.on('load', function(loader, node){
alert("Parent ID = [" +node.attributes.id+ "]");
loader.dataUrl = 'get_child_nodes.jsp?parentId='+node.attributes.id;
});
tree = new Ext.tree.TreePanel('tree-div', {
animate:true,
loader: loader,
enableDD:false,
containerScroll: true
});
// Setting the root node
var root = new Ext.tree.AsyncTreeNode({
text: 'Select a Parent',
draggable:false,
id:'source'
});
tree.setRootNode(root);
// Render the tree
tree.render();
root.expand();
});
</script>
As can be seen from the code, the first load of the tree loads the data from the 'get_parent_nodes.jsp'. When the user now clicks on the first level nodes, I make a AJAX call to get the data from the ''get_child_nodes.jsp?parentId='+node.attributes.id". Let me know if this is correct.
The problem that I am facing is that, when I click on any of the first level node, the data for that node is not retrieved. When I click on some other first level node, the data for the prvious click is retrieved and so on.
Can you let me know where am I making a mistake. The other question is that we have some other requirement where we need to build a multi-level tree where the data for each level should be retrieved via AJAX calls that have different URLs for each level. How to dynamically change the URL for each level of data?
Regards,
Pradnesh
I am trying to us the Tree component of the Ext JS. My basic requirement is that the tree should load the first level of nodes on the first load. On clicking the first level of nodes, there should be an AJAX call that loads the children of that node. Following is the code that I have written:
<script type="text/javascript">
var tree;
Ext.onReady(function()
{
// Creating a new tree loader.
var loader = new Ext.tree.TreeLoader({dataUrl:'get_parent_nodes.jsp'});
// Setting the URL for retrieving the child elements.
loader.on('load', function(loader, node){
alert("Parent ID = [" +node.attributes.id+ "]");
loader.dataUrl = 'get_child_nodes.jsp?parentId='+node.attributes.id;
});
tree = new Ext.tree.TreePanel('tree-div', {
animate:true,
loader: loader,
enableDD:false,
containerScroll: true
});
// Setting the root node
var root = new Ext.tree.AsyncTreeNode({
text: 'Select a Parent',
draggable:false,
id:'source'
});
tree.setRootNode(root);
// Render the tree
tree.render();
root.expand();
});
</script>
As can be seen from the code, the first load of the tree loads the data from the 'get_parent_nodes.jsp'. When the user now clicks on the first level nodes, I make a AJAX call to get the data from the ''get_child_nodes.jsp?parentId='+node.attributes.id". Let me know if this is correct.
The problem that I am facing is that, when I click on any of the first level node, the data for that node is not retrieved. When I click on some other first level node, the data for the prvious click is retrieved and so on.
Can you let me know where am I making a mistake. The other question is that we have some other requirement where we need to build a multi-level tree where the data for each level should be retrieved via AJAX calls that have different URLs for each level. How to dynamically change the URL for each level of data?
Regards,
Pradnesh