PDA

View Full Version : Tree reload Problem, how to make a node selected ?



srxying
7 Jul 2010, 10:37 PM
The following is the function in one jsp.
-----------------------------------------------------
function reloadNode(tree){
var node = tree.getSelectionModel().getSelectedNode();
if(node!='undefined' && node!=tree.getRootNode()){
tree.getSelectionModel().getSelectedNode().parentNode.reload();
tree.getSelectionModel().select(node); // node.select();
}else if(node == tree.getRootNode()){
node.reload();
}
}
-----------------------------------------------------
what my purpose is, when i submit this jsp, i want to refresh the tree, and want the selected tree node to be kept selected. but the blue part doesn't work, neither select(node) nor node.select();
how could i do ? thanks a lot.

Condor
7 Jul 2010, 10:47 PM
1. Loading is asynchronous. You have to wait for the server to respond before the nodes are available (use the reload callback).
2. After reloading the node object doesn't exist anymore. You have to find the node with the same id and select it.

srxying
7 Jul 2010, 10:52 PM
Thanks Condor, that does make sense. I will try and let you know what's going on.

srxying
7 Jul 2010, 11:09 PM
function reloadNode1(tree){
var node = tree.getSelectionModel().getSelectedNode();
var nid = node.id;
alert("getNodeById.no1="+tree.getNodeById(nid));
if(node!='undefined' && node!=tree.getRootNode()){
tree.getSelectionModel().getSelectedNode().parentNode.reload();
//tree.getSelectionModel().select(node);
alert("node.text="+node.text+",node.id="+nid);
alert("getNodeById.no2="+tree.getNodeById(nid));

}else if(node == tree.getRootNode()){
node.reload();
}
}
i do the above modification. and the first alert works fine, tree can get the node throught getNodeByID;
the second alert works fine, the node text and id can be printed;
but the third alert doesn't work, "undefined" poped out.
why ? why ? why ?