Tree structure file generation method and device, electronic equipment and storage medium
By parsing the tree structure source file and setting the counter value, combined with the CSS selector to generate the target file, the problem of too small click range of deep-level nodes is solved, and convenient deep-level node operations and layer-by-layer indentation effects are achieved.
Patent Information
- Application Number
- CN202410786918.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-10-29
AI Technical Summary
When the existing technology displays a tree structure, the click range of deep-level nodes is too small, resulting in inconvenient operation.
By parsing the source file of the tree structure, the nodes at each level are determined, and the counter value is set according to the node level, and the target file is generated by combining various CSS selectors to achieve layer-by-layer indentation without reducing the click range of deep-level nodes.
It effectively expands the click range of deep-level nodes, making it more convenient to click on deep-level nodes, and at the same time achieves the effect of layer-by-layer indentation.
Smart Images

Figure CN118860481A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for generating a tree-structured file. Background Art
[0002] In daily front-end development, it is often necessary to display tree structures, such as directory trees. In order to reflect the hierarchy of the tree structure, it is usually necessary to indent layer by layer during display. In existing methods, the inner margins of nodes at each level are usually calculated according to the level of the current node. Indentation is achieved layer by layer through different inner margins. Or, indentation is achieved layer by layer by relative positioning of nodes at different levels. However, these solutions lead to the problem that the click range of deep-level nodes is too small. Summary of the invention
[0003] Embodiments of the present disclosure provide a tree-structured file generation method, device, electronic device, and storage medium.
[0004] In a first aspect, an embodiment of the present disclosure provides a method for generating a tree structure file, comprising: obtaining a tree structure source file; parsing the tree structure source file to determine the nodes of each level in the tree structure; determining the numerical value corresponding to each node according to the level of each node; determining the tree structure target file according to the numerical value corresponding to each node and multiple CSS selectors.
[0005] In a second aspect, an embodiment of the present disclosure provides a tree-structured file generating device, comprising: a file acquisition unit, configured to acquire a tree-structured source file; a node determination unit, configured to parse the tree-structured source file and determine the nodes of each level in the tree structure; a value determination unit, configured to determine the value corresponding to each node according to the level of each node; and a file determination unit, configured to determine a tree-structured target file according to the value corresponding to each node and a plurality of CSS selectors.
[0006] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising a memory, a processor, a bus, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the tree structure file generation method described in the first aspect is implemented.
[0007] In a fourth aspect, an embodiment of the present disclosure provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the tree structure file generation method as described in the first aspect.
[0008] By applying the technical solution disclosed in the present invention, the tree structure source file can be parsed to determine the nodes of each level, and then the counter value corresponding to each node can be determined according to the level of each node. Finally, the tree structure destination file is determined according to the value corresponding to each node and a variety of CSS selectors. By setting different counter values for nodes of each level, the indentation of nodes of different levels can be achieved without reducing the scope of deep nodes, making it easier to click on deep nodes.
[0009] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0011] Figure 1 A flowchart of an embodiment of a method for generating a tree structure file disclosed in the present invention;
[0012] Figure 2 A flowchart of another embodiment of the tree structure file generation method disclosed in the present invention;
[0013] Figure 3 A schematic diagram of the structure of an embodiment of a tree structure file generating device disclosed in the present invention;
[0014] Figure 4 A schematic diagram of the structure of an embodiment of an electronic device disclosed herein. DETAILED DESCRIPTION
[0015] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present disclosure. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present disclosure belongs.
[0016] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present disclosure. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0017] In the absence of conflict, the embodiments in the present disclosure and the features in the embodiments may be combined with each other.
[0018] In order to make the technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0019] Figure 1 A process 100 of an embodiment of a method for generating a tree structure file of the present disclosure is shown.
[0020] like Figure 1 As shown, the tree structure file generation method of this embodiment may include the following steps:
[0021] Step 101, obtaining a tree structure source file.
[0022] In this embodiment, the execution subject of the tree structure file generation method can first obtain a tree structure source file. Here, the tree structure source file can be various types of files generated by front-end development, such as JSON format files.
[0023] Step 102: parse the tree structure source file to determine the nodes at each level in the tree structure.
[0024] After obtaining the tree structure source file, it can be parsed to determine the nodes at each level in the tree structure. Specifically, the tree structure source file can be parsed into a file in a specified format, such as an HTML file or an XML file. Then, the statements in the file in the specified format are analyzed to determine the nodes at each level in the tree structure. Alternatively,
[0025] It can be understood that the above tree structure may include node identifiers and node levels.
[0026] Step 103, determining the value corresponding to each node according to the level of each node.
[0027] In this embodiment, after determining the level of each node, the counter value corresponding to each node can be determined. The value here can be understood as the distance that each node needs to be indented. Specifically, the level of each node can be multiplied by a preset value, and the product obtained is the value corresponding to the node. Alternatively, the level of each node can be directly used as the corresponding value.
[0028] Step 104, determining the tree structure destination file according to the value corresponding to each node and a plurality of CSS selectors.
[0029] After determining the values corresponding to each node, a variety of CSS selectors can be combined to determine the tree structure destination file. Specifically, the class selector and tag selector in the CSS selector can be added to each node. Then, according to the values of each node, a pseudo-element selector is added to each node. The number of pseudo-elements is the same as the number of the above values. In this way, different values can be indented for nodes at different levels. It is understandable that the tree structure destination file can be a CSS file.
[0030] The tree structure file generation method provided by the above embodiment of the present disclosure can parse the tree structure source file, determine the nodes of each level, and then determine the counter value corresponding to each node according to the level of each node. Finally, the tree structure destination file is determined according to the value corresponding to each node and a variety of CSS selectors. By setting different counter values for nodes of each level, the indentation of nodes of different levels is achieved, but the scope of deep nodes will not be reduced, making it easier to click on deep nodes.
[0031] Continue to see Figure 2 , which shows a process 200 of another embodiment of the tree structure file generation method according to the present disclosure. Figure 2 As shown, the method in this embodiment may include the following steps:
[0032] Step 201, obtaining a tree structure source file.
[0033] Step 202: Parse the tree structure source file into an HTML file and determine the nodes of each level in the tree structure.
[0034] In this embodiment, the tree structure source file can be parsed into an HTML file. Then, the HTML file is parsed to determine the nodes of each level in the tree structure.
[0035] Step 203, determining the value corresponding to each node according to the level corresponding to each node and the preset unit value.
[0036] Here, a unit value of the indentation distance may be preset, and the unit value may be a difference between the indentation distances of two nodes at adjacent levels.
[0037] Step 204, add a class selector and a label selector for each level node; add a counter before each level node, and set the value of the counter to the counter value corresponding to the node.
[0038] In this embodiment, a class selector and a label selector can be added to each level node. Here, a class selector can be added to each level node and defined. At the same time, a label selector can also be added to each level node. Then, a counter is added before each level node, and the value of the counter is set to the value corresponding to the node.
[0039] In some optional implementations of this embodiment, when adding class selectors and label selectors, first type class selectors and label selectors may be added for nodes at each level. For a certain node, if the node also includes subordinate nodes, a second type class selector may be added under the node.
[0040] In some optional implementations of this embodiment, a counter may be added to the first type of node, and a pseudo-element selector may be added to the second type of node, so as to display the value corresponding to the node before the second type of node.
[0041] In some optional implementations of this embodiment, the color of the pseudo-element may be set to transparent, so that the indented portion before the node can be hidden.
[0042] The following is a detailed explanation of the method disclosed in the present invention using specific codes:
[0043] <div class="reset">
[0044] <div class="item">First level directory 1
[0045] <div class="reset">
[0046] <div class="item"> Secondary directory 1
[0047] <div class="item">Secondary directory 2
[0048] <div class="reset">
[0049] <div class="item"> Level 3 Directory 1
[0050] <div class="item"> Level 3 Directory 2
[0051] <div class="item"> Level 3 Directory
[0052]
[0053]
[0054] <div class="item"> Secondary directory 3
[0055]
[0056]
[0057] <div class="item"> First level directory 2
[0058] <div class="item">First level directory 3
[0059] <div class="reset">
[0060] <div class="item"> Secondary directory 1
[0061]
[0062]
[0063]
[0064] In this embodiment, the tree structure can be parsed into HTML format first, and then a class selector class is added to each level of node to define item. The list under each node uses the class selector class to define the reset node and is wrapped with a tag selector div.
[0065] Then, add the style .reset{counter-reset:count;} to the div node with class reset, so that it is defined as a counter named 'count'.
[0066] Add a pseudo element .item::before{content:counters(count,'--');} to the div node with class item, and the calculator value will be displayed in front of the node. The calculator value will be longer as the level goes deeper.
[0067] Then, set the pseudo-element color to transparent.item::before{color:transparent;}, so that the calculator value will not be displayed but still occupy a certain width before the node, achieving the effect of indenting layer by layer.
[0068] The tree structure file generation method provided by the above-mentioned embodiment of the present disclosure can realize layer-by-layer indentation through CSS counter, and each tree node is of full width without the need to use pseudo elements to expand the click range; and this solution is completely based on CSS style and is easy to implement.
[0069] Further references Figure 3 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a tree structure file generation device. Figure 1 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0070] like Figure 3 As shown, the tree structure file generating device 300 of this embodiment includes: a file acquiring unit 301 , a node determining unit 302 , a value determining unit 303 and a file determining unit 304 .
[0071] The file acquisition unit 301 is configured to acquire a tree-structured source file.
[0072] The node determination unit 302 is configured to parse the tree structure source file to determine the nodes at each level in the tree structure.
[0073] The value determination unit 303 is configured to determine the value corresponding to each node according to the level of each node.
[0074] The file determination unit 304 is configured to determine the tree-structured target file according to the values corresponding to each node and a plurality of CSS selectors.
[0075] In addition, in the technical solution of the present application, an electronic device is also proposed.
[0076] Figure 4 A schematic structural diagram of an electronic device provided by an embodiment of the present disclosure is shown.
[0077] like Figure 4 As shown, the electronic device may include a processor 401, a memory 402, a bus 403, and a computer program stored in the memory 402 and executable on the processor 401, wherein the processor 401 and the memory 402 communicate with each other via the bus 403. When the processor 401 executes the computer program, the steps of implementing the above method include, for example: obtaining a tree structure source file; parsing the tree structure source file to determine the nodes of each level in the tree structure; determining the value corresponding to each node according to the level of each node; determining the tree structure destination file according to the value corresponding to each node and a plurality of CSS selectors.
[0078] In addition, in one embodiment of the present disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented, for example, including: obtaining a tree structure source file; parsing the tree structure source file to determine the nodes of each level in the tree structure; determining the value corresponding to each node according to the level of each node; determining the tree structure destination file according to the value corresponding to each node and multiple CSS selectors.
[0079] In summary, in the technical solution disclosed in the present invention, the tree structure source file can be parsed to determine the nodes of each level, and then the counter value corresponding to each node is determined according to the level of each node. Finally, the tree structure destination file is determined according to the value corresponding to each node and a variety of CSS selectors. By setting different counter values for nodes of each level, the indentation of nodes of different levels is achieved, but the scope of deep nodes will not be reduced, making it easier to click on deep nodes.
[0080] The above description is only a preferred embodiment of the present disclosure and is not intended to limit the present disclosure. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure shall be included in the scope of protection of the present disclosure.
Claims
1. A method for generating a tree structure file, comprising: Get the tree structure source file; Parsing the tree structure source file to determine the nodes at each level in the tree structure; According to the level of each node, determine the value corresponding to each node; According to the corresponding values of each node and multiple CSS selectors, the tree structure destination file is determined.
2. The method according to claim 1, wherein: The step of parsing the tree structure source file to determine nodes at each level in the tree structure includes: Parse the tree structure source file into an HTML file and determine the nodes at each level in the tree structure.
3. The method according to claim 1, wherein: The determining, according to the nodes and the levels corresponding to the nodes, the counter values corresponding to the nodes includes: According to the level corresponding to each node and the preset unit value, the counter value corresponding to each node is determined.
4. The method according to claim 1, wherein: Determining the tree structure destination file according to the values corresponding to each node and a plurality of CSS selectors includes: Add class selectors and label selectors to nodes at each level; Add a counter before each level node, and set the value of the counter to the value corresponding to the node.
5. The method according to claim 4, wherein: Adding class selectors and label selectors to nodes at each level includes: Add the first type of class selector and label selector to each level of nodes; For a single node, in response to determining that the node includes a lower-level node, a class selector of the second type is added under the node.
6. The method according to claim 5, wherein: Determining the tree structure destination file according to the values corresponding to each node and a plurality of CSS selectors includes: adding a counter for nodes of the first type; A pseudo-element selector is added to the second type of node to display the value corresponding to the node before the second type of node.
7. A tree structure file generating device, comprising: A file acquisition unit is configured to acquire a tree-structured source file; A node determination unit is configured to parse the tree structure source file to determine nodes at each level in the tree structure; A value determination unit is configured to determine a value corresponding to each node according to the level of each node; The file determination unit is configured to determine the tree-structured target file according to the values corresponding to each node and a plurality of CSS selectors.
8. An electronic device comprising a memory, a processor, a bus, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the tree structure file generation method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the tree structure file generation method according to any one of claims 1 to 6 is implemented.
