Home >Web Front-end >JS Tutorial >How to select the last node selected before refreshing by default after ExtJS refresh_extjs

How to select the last node selected before refreshing by default after ExtJS refresh_extjs

WBOY
WBOYOriginal
2016-05-16 16:53:32996browse

After operating on tree nodes, it is often necessary to perform a reload operation to refresh the tree, but many businesses need to select the last selected node by default after the tree is refreshed. In this way, the information of the previously selected node must be saved first, and then expanded through the node information again to this node layer by layer after reload.

After querying for a long time, 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 it layer by layer starting from the root node through the path until the last node.

The completed code is as follows:
The first is the method in extjs3.x version:

Copy code The code is as follows:

//Get the selected node
var node = tree.getSelectionModel().getSelectedNode();
if(node ​​== null) { //No re-selected node Load tree
tree.getRootNode().reload();
} else { //Reload the tree and select the last selected node 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
Copy code The code is as follows:

idPath = selNode.getPath("id");
tree. getStore().load({
node: tree.getRootNode(),
callback: function () {
tree.expandPath(idPath, 'id');
}
}) ;

It should be noted that the node in the json data of the tree returned in the background must contain the id attribute. Originally I did not have this attribute, but I changed the parameter in the getPath method to another attribute. Facts have proved that this is not effective, and finally the id attribute was added to json to succeed.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn