Disclosure of Invention
The application provides a method and a device for controlling check boxes, which are used for solving the problems that the existing multilevel check boxes are complex to process and different systems influence each other.
In a first aspect, to achieve the above object, the present application provides a method of controlling a check box, the method including:
acquiring a target state of a target check box and a first attribute of the target check box, wherein the first attribute is a preset attribute except a fixed attribute of the target check box;
analyzing the first attribute to obtain a mapping table, wherein the mapping table comprises at least one fixed attribute value corresponding to at least one following check box;
traversing the mapping table to obtain the following check boxes corresponding to the mapping table;
converting the current state of the following check box to be consistent with the target state of the target check box.
Further, the target state includes a selected state or a cancelled state.
Further, after the obtaining the target status of the target check box and the first attribute of the target check box, the method further includes:
and acquiring the fixed attribute value of the target check box.
Further, before the obtaining the target status of the target check box and the first attribute of the target check box, the method further includes:
selecting a target check box, and adding the first attribute to the target check box;
acquiring at least one fixed attribute value corresponding to at least one following check box;
and adding the fixed attribute value in the first attribute to form a mapping table.
Further, after the adding the fixed attribute value to the first attribute and forming a mapping table, the method further includes:
the target check box binds a change event with the following check box.
In a second aspect, the present application further provides an apparatus for controlling a check box, the apparatus comprising a control unit configured to:
acquiring a target state of a target check box and a first attribute of the target check box, wherein the first attribute is a preset attribute except a fixed attribute of the target check box;
analyzing the first attribute to obtain a mapping table, wherein the mapping table comprises at least one fixed attribute value corresponding to at least one following check box;
traversing the mapping table to obtain the following check boxes corresponding to the mapping table;
converting the current state of the following check box to be consistent with the target state of the target check box.
Further, the target state includes a selected state or a cancelled state.
Further, the control unit is further configured to: and acquiring the fixed attribute value of the target check box.
Further, the device also comprises a preset unit used for:
selecting a target check box, and adding the first attribute to the target check box;
acquiring at least one fixed attribute value corresponding to at least one following check box;
and adding the fixed attribute value in the first attribute to form a mapping table.
Further, the preset unit is further configured to bind the target check box with the following check box for a change event.
In a third aspect, to achieve the above object, the present application provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of any one of the methods of controlling checkboxes of the first aspect.
In a fourth aspect, to achieve the above object, the present application provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method for controlling check boxes according to any one of the first aspect when executing the program.
According to the technical scheme, the method and the device for controlling the check boxes, provided by the embodiment of the application, are characterized in that the target state of the target check box and the first attribute of the target check box are obtained; analyzing the first attribute to obtain a mapping table; traversing the mapping table to obtain the following check boxes corresponding to the mapping table; the current state of the following check box is converted into the state consistent with the target state of the target check box, the purpose of controlling the check box is achieved through the execution steps, the check box does not need to be divided into an upper-level and a lower-level relation, the control is simple, and data among different branches can be controlled mutually.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Detailed Description
The features and advantages of the present application will become more apparent and appreciated from the following detailed description of the application.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. While the various aspects of the embodiments are presented in drawings, the drawings are not necessarily drawn to scale unless specifically indicated.
In the description of the present application, it should be noted that the terms "upper", "lower", "inner", "outer", "front", "rear", "left" and "right" and the like indicate orientations or positional relationships based on operational states of the present application, and are only used for convenience of description and simplification of description, but do not indicate or imply that the referred device or element must have a specific orientation, be constructed in a specific orientation and be operated, and thus, should not be construed as limiting the present application. Furthermore, the terms "first," "second," "third," and "fourth" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
The prior art generally defines a fixed attribute such as id on a check box of parent data, and then defines another fixed attribute such as name on a check box of child data, and the attribute value of the name is equal to the id value. Recursive processing is performed when checking or canceling operations are performed on check boxes of data. As shown in fig. 1, this is a method of defining id, name attributes to implement control check boxes:
firstly, id and name of different data hierarchical relations need to be defined in advance when the data object is used, each check box with the name value equal to the id value belongs to the sub-level data, and each check box is called an operable data object. That is, id and name are well defined on the check box, and the attribute values of id and name are relied on to distinguish the upper and lower hierarchical relations of the data, for example, id is "one", and the sub-level name corresponding to it is "one".
Second, click events (click) or change events (change) are rebinding for each actionable object.
Finally, when the user clicks the check box, acquiring the id and the name of the current check box; all child level data objects are found down through id first and have their child level data object state (checked/canceled) changed following the state of parent level data.
And finding all parent data objects by the name in an upward recursion manner, traversing all child data objects under the parent data objects, and calculating whether the parent data objects can be selected or cancelled.
The above scheme has several problems:
the use is inconvenient, the id and the name of each check box need to be manually defined during use, and the id and the name have to be in a top-bottom hierarchical relationship and then are used after event binding.
The association between the different hierarchy data levels cannot be made, because the association between each data level is associated by id and name, so the data of other branches cannot be associated with the current operation object. If the association needs to be made, event snooping (click/change) needs to be handled separately for a certain data node.
Different system data influence each other, for example, the secondary data B2 under the primary data A1 needs to follow the state change of the C2 with the same level as B2 when being selected or cancelled. For example, there are two levels of data a and B, the data a and B do not have a relationship between upper and lower levels, a has its own sub-level a1, B also has its own sub-level B1, and when the state of the sub-level a1 of a changes, the state of the sub-level B1 of B also needs to change accordingly. For example, when A1 is selected, B1 is required to be changed to a selected state
To solve the above problems, the present application provides a method and an apparatus for controlling a check box, and the following describes in detail a specific embodiment of the present application with reference to the accompanying drawings.
Fig. 2 is a schematic flowchart of a method for controlling check boxes according to a first embodiment of the present application, and as shown in fig. 2, the method includes steps S101 to S104.
S101: and acquiring a target state of a target check box and a first attribute of the target check box, wherein the first attribute is a preset attribute except a fixed attribute of the target check box.
The target check box is an object which needs to be operated currently, the current state of the target check box comprises a checking state or a canceling state, and the target state comprises the checking state or the canceling state, namely the target check box can be switched from the checking state to the canceling state, or the target check box can be switched from the canceling state to the checking state.
The step of setting the first attribute as shown in fig. 3 specifically includes:
s001: and selecting a target check box, and adding the first attribute to the target check box.
S002: and acquiring at least one fixed attribute value corresponding to at least one following check box.
S003: and adding the fixed attribute value in the first attribute to form a mapping table.
S004: the target check box binds a change event with the following check box.
During specific implementation, a first attribute synchro is added to the target check box, the attribute value of the fixed attribute corresponding to the required follow check box, such as the name value, is added to the synchro attribute value in the json data format to form a mapping table, for example:
synchro='{"team[]":["team"],"team_role[]":["team_role"],"team_team"]}'。
after the first attribute is preset, a change event needs to be set, such as acquiring all objects with the sync attribute,
(inputObj): var inputObj ═ ($ ("input [ type ═ checkbox' ] [ sync ]"); binding change event to inputObj (change): bind ('change', function () {/}).
S102: and analyzing the first attribute to obtain a mapping table, wherein the mapping table comprises at least one fixed attribute value corresponding to at least one following check box.
S103: and traversing the mapping table to obtain the following check box corresponding to the mapping table.
If the json character string is analyzed by using JavaScript, converting the json character string str into the json object only by calling a function JSON.
S104: converting the current state of the following check box to be consistent with the target state of the target check box.
For example, in the target check box a, when the state of a changes, the value of the sync is traversed to find a following check box whose name and value exist in the sync, and the state of the following check box whose name is "team [ ]" and value is "team" also changes.
The json format of the attribute values of the first attribute sync is used for { "name": value1"," value2"] } because there are a plurality of check boxes of the same name but the values thereof are different.
For data objects of different systems, only the name and value of the data object need to be added into the current sync value, so that the data object can be controlled, such as: when the check box A is checked and cancelled, the check box B also needs to have a corresponding change state, and the effect can be realized by only adding the name and the value of A into the sync attribute of B. In the application, parent-level data and child-level data do not need to be distinguished, and whether the states of other check boxes need to be changed or not is judged completely through the attribute values of the synchro.
In another specific embodiment, as shown in fig. 4, after the obtaining the target status of the target check box and the first attribute of the target check box, the method further includes, S105: and acquiring the fixed attribute value of the target check box.
At this time, the target check box is a following check box as other target check boxes, and if the fixed attribute value of the target check box and the other target check boxes form a mapping relationship, the state of the target check box is changed accordingly.
Corresponding to the embodiment of the method for controlling the check box, the application also provides an embodiment of a device for controlling the check box. Referring to fig. 5, a schematic structural diagram of an apparatus for controlling a check box provided in an embodiment of the present application is shown, where the apparatus includes:
the system comprises a presetting unit 100, a first attribute adding unit and a second attribute adding unit, wherein the presetting unit 100 is used for selecting a target check box and adding the first attribute to the target check box; acquiring at least one fixed attribute value corresponding to at least one following check box; adding the fixed attribute value to the first attribute to form a mapping table; the target check box binds a change event with the following check box.
The system further comprises a control unit 200, which is used for acquiring a target state of a target check box and a first attribute of the target check box, wherein the first attribute is a preset attribute except a fixed attribute of the target check box;
analyzing the first attribute to obtain a mapping table, wherein the mapping table comprises at least one fixed attribute value corresponding to at least one following check box;
traversing the mapping table to obtain the following check boxes corresponding to the mapping table;
converting the current state of the following check box to be consistent with the target state of the target check box;
and acquiring the fixed attribute value of the target check box.
According to the method and the device for controlling the data relation of the check boxes, the target state of the target check box and the first attribute of the target check box are obtained; analyzing the first attribute to obtain a mapping table; traversing the mapping table to obtain the following check boxes corresponding to the mapping table; the current state of the following check box is converted into the state consistent with the target state of the target check box, the purpose of controlling the check box is achieved through the execution steps, the check box does not need to be divided into an upper-level and a lower-level relation, the control is simple, and data among different branches can be controlled mutually.
According to the method for controlling the check boxes, the embodiment of the application also provides a readable storage medium and a computer device. The readable storage medium has stored thereon an executable program which, when executed by a processor, implements the steps of the above-described method of controlling check boxes; the computer device comprises a memory, a processor and an executable program stored on the memory and capable of running on the processor, and the steps of the method for controlling the check boxes are realized when the processor executes the program.
The present application has been described in detail with reference to specific embodiments and illustrative examples, but the description is not intended to limit the application. Those skilled in the art will appreciate that various equivalent substitutions, modifications or improvements may be made to the presently disclosed embodiments and implementations thereof without departing from the spirit and scope of the present disclosure, and these fall within the scope of the present disclosure. The protection scope of this application is subject to the appended claims.