The general idea of using recursive algorithms to select a tree cascade is that of recursive algorithms.
Article copyright by the author Li Xiaohui and blog park a total of, if reproduced Please clearly indicated in the source: http://www.cnblogs.com/naaoveGIS/
1. Background
In a project, it is found that when the tree is added with checkbox, initialization of this tree will be particularly slow. The number of nodes on the site tree is at most three layers, and the total number of nodes is more than 200. After investigation, the cascade check parameter is enabled for the tree parameters, which leads to a cascade judgment every time a node is initialized during tree initialization. This is caused by low efficiency.
After selecting the cascade check box, you need to solve the following problems:
During initialization, You must select the logic for cascade at the front-end or back-end.
2. Background cascading selection algorithm during initialization
When the data in the tree is initialized and read from the backend, We can first obtain the selected status of each subnode, check whether the parent node is selected for the overall determination of the constructed tree structure. The recursive algorithm is roughly as follows:
3. After initialization, the front-end cascade Selection Algorithm (only to be checked)
The tree has two statuses: select one, and select one. Here, only the check process is considered. The algorithm used to check the process is the same as the algorithm used to check the process.
When you select any node on the tree after tree initialization, you need to complete the following two cascade judgments:
A. If the selected node is a parent node, all its child nodes must be checked, and its parent node must also be cascaded.
B. If normal subnodes are selected, the parent node must perform cascade judgment.
In a unified manner, two cascade calculation methods are required to judge in the upward direction and in the downward direction:
3.1 cascade Calculation Method for parent nodes
3.2 cascade judgment for sub-nodes
4. Note
In recursive algorithms, the level parameter is a very important parameter and is very useful in controlling the operation logic.
----- Welcome to reprint, but retain the copyright, Please clearly indicated in the source: http://www.cnblogs.com/naaoveGIS/