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

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.