This article describes how to select the last selected node after ExtJS refresh by default, if you need a reload operation, you may need to reload the tree after performing operations on the tree node. However, many businesses need to select the last selected node by default after the tree refreshing. In this way, you must first save the information of the previous selected node, and then expand it layer by layer through the node information after reload.
After searching for a long time, we finally found a feasible solution, that is, to record the node location information through the Node path, and then start layer-by-layer expansion from the root node through the path until the last node.
The completed Code is as follows:
First, the method in extjs3.x:
The Code is as follows:
// Obtain the selected node
Var node = tree. getSelectionModel (). getSelectedNode ();
If (node = null) {// The overload tree is not selected
Tree. getRootNode (). reload ();
} Else {// reload the tree and select the Node Selected last time by default
Var path = node. getPath ('id ');
Tree. getLoader (). load (tree. getRootNode (),
Function (treeNode ){
Tree. expandPath (path, 'id', function (bSucess, oLastNode ){
Tree. getSelectionModel (). select (oLastNode );
});
}, This );
}
Different from Extjs3.0, Extjs4.2 is written as follows:
The Code is as follows:
IdPath = selNode. getPath ("id ");
Tree. getStore (). load ({
Node: tree. getRootNode (),
Callback: function (){
Tree. expandPath (idPath, 'id ');
}
});
Note that the json data point returned by the background must contain the id attribute. I didn't have this attribute, but I changed the parameter in the getPath method to another attribute. It turns out that this is ineffective, and the id attribute is added to json.