The general idea of using recursive algorithms to select a tree cascade is that of recursive algorithms.

Source: Internet
Author: User

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/

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.