Article copyright by the author Xiaohui Li is and the blog park, if reproduced please clearly indicate the source: http://www.cnblogs.com/naaoveGIS/
1. Background
In a project, it is found that when a checkbox is added to a tree, it is very slow to initialize it. The nodes in the field tree have a depth of three layers, and the total number of nodes is more than 200. After troubleshooting, the parameter of the tree is turned on the cascade tick, resulting in the initialization of a node at the time of each initialization of a cascade judgment, so inefficient.
Now, after the cascade is removed, there are several issues that need to be addressed:
The cascade tick logic needs to be completed at the front or back end of the initialization.
- When you manually tick the nodes on the tree, you need to make a cascading decision.
- When you click the parent node, all child nodes need to be selected.
- When you click a child node, you need to determine whether the parent node and the parent group node must be selected.
2. Background cascade selection algorithm at initialization
When the data initialization of the tree is read from the backend, we can first obtain the selected state of each child node, and after all, the tree structure is constructed to determine whether the parent node is checked. The recursive algorithm is roughly as follows:
3. Cascade selection algorithm after initialization (check only)
The tree has two states, one is tick, the other is to tick. Only the process of checking is considered here. The algorithm to check the process is the same as the tick algorithm.
When the tree is initialized, the following two cascading judgments are required when selecting any node in the tree:
A. If the check is a parent node, all of its child nodes need to be checked, and the parent node should also do a cascade judgment.
B. If the tick is a normal child node, its parent node is to do a cascading judgment.
Unify is, need to do two cascade algorithm, respectively is the upward direction judgment, and the downward direction judgment:
3.1 cascading algorithms for parent nodes
3.2 Cascading judgment for child nodes
4. Note
Recursive hierarchy (level) parameters are a very important parameter in recursive algorithm, which is very useful in controlling operation logic.
-----Welcome reprint, but retain the copyright, please indicate the source in obvious place: http://www.cnblogs.com/naaoveGIS/
The general idea of the cascade tick of tree by recursive algorithm