The general idea of the cascade tick of tree by recursive algorithm

Source: Internet
Author: User

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.

    1. When you manually tick the nodes on the tree, you need to make a cascading decision.
    2. When you click the parent node, all child nodes need to be selected.
    3. 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

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.