How to select the last selected node by default after the ExtJS refresh

  • 2020-03-30 02:30:44
  • OfStack

Reload is often required to refresh the tree after tree node operation, but many businesses need to select the last selected node by default after tree refresh. In this way, we must first save the information of the previous selected node, and then expand to this node layer by layer through the information of the node after reload.

After a long search, I finally found a feasible solution, which is to record the location information of the node through the path of the node, and then expand layer by layer from the root node through the path until the last node.

The completed code is as follows:
The first is the method in the extjs3.x version:
//Gets the selected node
var node = tree.getSelectionModel().getSelectedNode(); 
if(node == null) { //The overloaded tree is not selected
} else { //Reloads the tree and selects the last selected node by default
var path = node.getPath('id'); 
function(treeNode) { 
tree.expandPath(path, 'id', function(bSucess, oLastNode) { 
}, this); 

Unlike Extjs3.0, Extjs4.2 is written as follows
idPath = selNode.getPath("id"); 
node: tree.getRootNode(), 
callback: function () { 
tree.expandPath(idPath, 'id'); 

It is important to note that the json data point of the tree returned in the background must contain an id attribute, which I did not have originally, but I changed the parameter in the getPath method to another attribute. This proved to be ineffective, and it was only successful to add an id attribute to json.

Related articles: