PDA

View Full Version : [solved] load node data of tree dynamically



swl401
4 Nov 2009, 12:43 AM
i want to get first-stage child just when click the root node. then get the second-stage child when click the node of first-stage child. etc
i've tried two ways,but they don't work.

1. first way's code below

Ext.onReady(function() {
var tree = new Ext.tree.TreePanel({
renderTo : Ext.getBody(),
width : 200,
height : 500,
autoScroll : true,
animate : true,
loader : {
dataUrl : 'get-nodes.php'
},
root : {
text : 'Ext JS'
}
});
});

code in page get - nodes.php

[{
text : '2A folder Node',
dataUrl : 'get-nodes1.php'
}]

this case load first-stage node is ok, then it's can't load the second node correctly when click the first-stage node.

2. second way's code below

Ext.onReady(function() {
var tree = new Ext.tree.TreePanel({
renderTo : Ext.getBody(),
width : 200,
height : 500,
autoScroll : true,
animate : true,
loader : {
dataUrl : 'a.jsp',// use for complete this request, the page a.jsp isn't exist.
isLoaded : true,
directFn : function() {
Ext.Ajax.request({
url : "get-nodes.php",
success : function(resp) {
tree.root
.appendChild(resp.responseText);
}
});
}
},
root : {
text : 'Ext JS'
}
});
});

code in page get-nodes.php

[{
text : '2A folder Node',
loader : {
directFn : function() {
Ext.Ajax.request({
url : "get-nodes1.php",
success : function(resp) {
//node.appendChild(resp.responseText);
}
});
}
},
}]

on this case, it cant expand the child node,
i think i don't understand directFn well.

swl401
4 Nov 2009, 5:21 PM
anyone could show me how to use directFn of TreeLoader?
or we can't send a specified request on each child's node?

swl401
4 Nov 2009, 7:16 PM
Ext.onReady(function() {
var tree = new Ext.tree.TreePanel({
renderTo : Ext.getBody(),
width : 200,
height : 500,
autoScroll : true,
id : "test",
// useArrows: true,
animate : true,
loader : {
dataUrl : 'get-nodes.php',
baseParams : {
category:"category"
}
},
root : {
text : 'Ext JS'
}
});
});

code in page get-nodes.php

[{
text : '2A folder Node',
listeners : {
beforeload : function(treeLoader) {
treeLoader.getLoader().baseParams = {category:"changed"};
}
}
}]