Method and system for dynamically adding form items to form based on antd

By nesting the Table component in the Form.List component of the Ant Design component, the dynamic addition and deletion of form items in the table is realized, which solves the cumbersome table data collection and style adjustment problems in the existing technology, and improves UI development efficiency and code simplicity.

CN118838596APending Publication Date: 2024-10-25TONGFANG YOUYUN (BEIJING) TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411066319.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-10-25

AI Technical Summary

Technical Problem

The existing technology's method of dynamically adding form items to tables in front-end development is cumbersome, has poor data collection and maintenance performance, is cumbersome in style adjustment, and lacks elegant implementation methods.

Method used

Nest the Table component through the Form.List component of the Ant Design component, use the Table component as the main body of the loop, use the fields field of the Form.List component to assign the value to the dataSource of the Table component, define the columns table column properties and pass in the onClick event method to implement The table dynamically adds and deletes form items, reducing data storage changes and avoiding style adjustments.

Benefits of technology

It achieves the elegance and efficiency of dynamically adding form items to tables, simplifies the code, improves the efficiency of UI development and design, facilitates data collection and maintenance, and does not require additional control of table data changes or style adjustments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118838596A_ABST
    Figure CN118838596A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for dynamically adding form items to a form based on an antd, and the method comprises the following steps: nesting Table by using Form.List of an Antd Design, and taking the Table as a main body of a loop; the method comprises the following steps of: assigning a field field attribute parameter of Form.List to a dataSource data source parameter of a Table (Table); defining a Columns value of the Table, transmitting the Columns value into an onClick method of the Table, and transmitting a live function of Form.List into the onClick method of the Table; according to the method, a Button button definition is added under a Table, and an onClick method of the Table is transmitted into an add method of Form.List. According to the method, verification of each form item can be customized more flexibly, the form item can be dynamically added into the form elegantly, and the UI development and design efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of UI development and design; in particular, to a method and system for dynamically adding form items to a table based on antd. Background Art

[0002] React is one of the most influential UI development frameworks in the field of front-end development. React is a javascript library for building user interfaces launched by Facebook. React is mainly used to build UIs, making page development simpler and faster. React has a component-based development approach, building encapsulated components that manage their own states, and then combining components to form complex UIs.

[0003] Ant Design (antd is the abbreviation of Ant Design) is an enterprise-level UI design language and React component library. Ant Design aims to help developers build high-quality user interfaces. Ant Design's design philosophy is simplicity, focus and reliability. Ant Design provides a rich set of UI components, covering all levels from basic components to advanced components, including buttons, tables, input boxes, drop-down boxes, dialog boxes and other commonly used interface components to meet the needs of different projects. Currently in front-end development, the table component provided by Ant Design supports dynamic addition of rows, and the form component provided by Ant Design supports dynamic addition of form items.

[0004] At present, there are two main ways to implement dynamically adding form items to a table through the table components and form components provided by Ant Design: The first method: dynamically add rows through the table component. This implementation method requires manually adding rows in the data table and maintaining changes in the table data. When each form item in the table changes, the table data must change accordingly. The implementation method is cumbersome and data collection is fragmented, resulting in poor handling of table data in terms of data performance and data maintenance.

[0005] The second method: dynamically add form items through the Form.List component of the form component. This implementation method requires adjusting the form style to a table display style, and the header needs to be processed separately as data. In addition, when collecting data, the header data needs to be excluded. Since this implementation method first needs to adjust the form style and then exclude the header data, the implementation method is not elegant and the style change is also cumbersome.

[0006] Therefore, there is an urgent need to develop a method for realizing the effect of dynamically adding form items to a table in a simpler, more efficient and elegant manner in front-end development, so as to solve the above-mentioned difficulties and shortcomings of the prior art. Summary of the invention

[0007] In view of this, the purpose of the present invention is to propose a method and system for dynamically adding form items to a table based on antd, using the Form.List component of the Ant Design component to nest the Table component, using the Table component as the main body of the loop, and using as little code as possible to change the data slightly, reduce data storage changes, and facilitate the collection of the overall data of the form; the coding is simple, and there is no need to change to a table display style. Through the Form.List component combined with the Table component, the Form gets the complete table data of the List and collects the overall data of the form. There is no need to maintain changes in the table data, and the dynamic addition of form items to the table can be elegantly realized, thereby improving the efficiency of UI development and design.

[0008] The present invention provides a method for dynamically adding form items to a table based on antd, comprising the following steps: S1. Use the Form.List component (form component) of Antd Design component to nest the Table component (table component), and use the Table component as the main body of the loop; S2. Assign the fields attribute parameter of the Form.List component to the dataSource data source parameter of the Table component; S3. Define the parameter value of the columns table column attribute of the Table component, pass the parameter value of columns to the onClick event method of the Table component, and pass the remove column data function of the Form.List component to the onClick event method of the Table component; S4. Add a Button button definition under the Table component, and pass the onClick event method of the Table component to the add method of the Form.List component.

[0009] Furthermore, the parameter values ​​of the columns table column attributes of the definition Table component in the S3 step include: Define the title parameter, dataIndex parameter, key parameter, and render parameter of the columns table column attributes; Among them, the title parameter refers to the text displayed in the column header; The dataIndex parameter refers to the path corresponding to the column data in the data item, and supports querying nested paths through arrays; The Key parameter is the attribute used by the React component library to identify the uniqueness of each component; The Render parameter is a function. The render function returns a specific Input or select box, which is wrapped in a Form.Item form item. The name value of the Form.Item form item is set to the array format [field.name, custom name]. The first parameter value of [field.name, custom name] is filled in with the name of the field passed in by the Form.List component. The second parameter passes the name of the custom value to be displayed, which makes it easier for the Form.List component to collect data.

[0010] Furthermore, the step S3 of passing the parameter value of columns into the onClick event method of the Table component, passing the remove column data function of the Form.List component into the onClick event method of the Table component, and passing the remove column data function of the Form.List component into the onClick event method of the Table component includes: The operation display of deleting column data is defined in the render function. When clicked, the remove function of the Form.List component is passed to the onClick click event method of the Table component.

[0011] Furthermore, the name of the field passed into the onClick event method by the remove function is Field.name. In this way, the delete function of the Form.List component can be used directly without the need to control the table data additionally.

[0012] Furthermore, in the case where the unique dataIndex parameter has been set, the Key parameter is chosen to be ignored.

[0013] The present invention can completely use the Form.List component in combination with the Table component to dynamically add and delete form items in a table without the need to maintain more data changes and excessive table style processing.

[0014] The present invention also provides a system for dynamically adding form items to a table based on antd, and executes the method for dynamically adding form items to a table based on antd as described above, including: Form.List component nested Table component module: used to use Antd Design component's Form.List component to nest Table component, and use the Table component as the main body of the loop; The Form.List component assigns the Table component parameter module: used to assign the fields field attribute parameter of the Form.List component to the dataSource data source parameter of the Table component; The Remove function is passed into the onClick method module: it is used to define the parameter value of the columns table column attribute of the Table component, pass the columns parameter value into the onClick event method of the Table component, and pass the remove column data function of the Form.List component into the onClick event method of the Table component; The onClick method is passed into the add method module: it is used to add a Button button definition under the Table component, and pass the onClick event method of the Table component into the add method of the Form.List component.

[0015] Furthermore, the Remove function is passed into the onClick method module including: Define columns parameter value unit: used to define title parameter, dataIndex parameter, key parameter, and render parameter of columns table column attributes; the title parameter refers to the text displayed in the column header; the dataIndex parameter refers to the path corresponding to the column data in the data item, and supports querying nested paths through arrays; the Key parameter is the attribute used by the React component library to identify the uniqueness of each component; the Render parameter is a function, and the render function returns a specific Input or select box, which is wrapped in Form.Item form items. The name value of the Form.Item form item is set to the array format [field.name, custom name], and the first parameter value of [field.name, custom name] is filled in with the name of the field field passed in by the Form.List component, and the second parameter passes the name of the custom value to be displayed.

[0016] Furthermore, the Remove function is passed into the onClick method module and further includes: Defining deleting data and passing in onClick method unit: used to define the operation display of deleting column data in the render function. When clicked, the remove function of the Form.List component is passed to the onClick click event method of the Table component.

[0017] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method for dynamically adding form items to a table based on antd as described above are implemented.

[0018] The present invention also provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method for dynamically adding form items to a table based on antd as described above are implemented.

[0019] Compared with the prior art, the present invention has the following beneficial effects: The method and system for dynamically adding form items to a table based on antd provided by the present invention utilize the Form.List component of the Ant Design component to nest the Table component, use the Table component as the main body of the loop, and use as little code as possible to change the data in small amounts, reduce data storage changes, and facilitate the collection of the overall data of the form; through the Form.List component combined with the Table component, the Form obtains the complete table data of the List and collects the overall data of the form, without the need to maintain changes in the table data and without changing too many table display styles, and can more flexibly customize the verification of each form item, etc., and can elegantly realize the dynamic addition of form items to the table, with concise code and simple coding, and no need to change to a table display style, which is convenient for reading and subsequent maintenance, and effectively improves the efficiency of UI development and design. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the following detailed description of the preferred embodiment.The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting the invention.

[0021] In the attached picture: Figure 1 This is a flow chart of the method for dynamically adding form items to a table based on antd in the present invention; Figure 2 The figure is a schematic diagram of the structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0022] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and products consistent with some aspects of the present disclosure as detailed in the appended claims.

[0023] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0024] It should be understood that although the terms first, second, third, etc. may be used in the present disclosure to describe various information, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present disclosure, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0025] The embodiments of the present invention are described in further detail below.

[0026] The embodiment of the present invention provides a method for dynamically adding form items to a table based on antd. Figure 1 As shown, the following steps are included: S1. Use the Form.List component (form component) of Antd Design component to nest the Table component (table component), and use the Table component as the main body of the loop; The pseudo code for implementing step S1 in this embodiment is as follows: <Form.List name=“xxx”> {(fields, {add, remove}) => ( )} < / Form.List> S2. Assign the fields attribute parameter of the Form.List component to the dataSource data source parameter of the Table component; S3. Define the parameter value of the columns table column attribute of the Table component, pass the parameter value of columns to the onClick event method of the Table component, and pass the remove column data function of the Form.List component to the onClick event method of the Table component; Specifically, the parameter values ​​defining the columns table column attributes of the Table component include: the title parameter, dataIndex parameter, key parameter, and render parameter defining the columns table column attributes; Among them, the title parameter refers to the text displayed in the column header; The dataIndex parameter refers to the path corresponding to the column data in the data item, and supports querying nested paths through arrays; The Key parameter is a property used by the React component library to uniquely identify each component; if the unique dataIndex parameter has been set, the Key parameter can be ignored.

[0027] The Render parameter is a function. The render function returns a specific Input or select box, which is wrapped in a Form.Item form item. The name value of the Form.Item form item is set to the array format [field.name, custom name]. The first parameter value of [field.name, custom name] is filled in with the name of the field passed in by the Form.List component. The second parameter passes the name of the custom value to be displayed, which makes it easier for the Form.List component to collect data.

[0028] Specifically, passing the columns parameter value into the onClick event method of the Table component, passing the remove column data function of the Form.List component into the onClick event method of the Table component, and passing the remove column data function of the Form.List component into the onClick event method of the Table component include: The operation display of deleting column data is defined in the render function. When clicked, the remove function of the Form.List component is passed to the onClick event method of the Table component. The pseudo code for implementing this operation in this embodiment is as follows: const getColumns = (remove) => { return [ { title: "Key", render: (_, field) => ( <Form.Item name={[field.name, “key”]}> <input> < / Form.Item> ), }, ... { title: "Operation", render: (_, field) => ( <button onclick="{remove(field.name)}"> delete < / button> ), } ]; }; The name of the field passed to the onClick event method by the remove function is Field.name. In this way, the delete function of the Form.List component can be used directly without the need to control the table data additionally.

[0029] S4. Add a Button button definition under the Table component, and pass the onClick event method of the Table component to the add method of the Form.List component.

[0030] The pseudo code for implementing step S4 in this embodiment is as follows: <Form.List name=“xxx”> {(fields, {add, remove}) => ( <> <button onclick="{add}"> Add to< / button> )} < / Form.List> The embodiment of the present invention also provides a system for dynamically adding form items to a table based on antd, and executes the method for dynamically adding form items to a table based on antd as described above, including: Form.List component nested Table component module: used to use Antd Design component's Form.List component to nest Table component, and use the Table component as the main body of the loop; The Form.List component assigns the Table component parameter module: used to assign the fields field attribute parameter of the Form.List component to the dataSource data source parameter of the Table component; The Remove function is passed into the onClick method module: it is used to define the parameter value of the columns table column attribute of the Table component, pass the columns parameter value into the onClick event method of the Table component, and pass the remove column data function of the Form.List component into the onClick event method of the Table component; The onClick method is passed into the add method module: it is used to add a Button button definition under the Table component, and pass the onClick event method of the Table component into the add method of the Form.List component.

[0031] The Remove function is passed into the onClick method module including: Define columns parameter value unit: used to define the title parameter, dataIndex parameter, key parameter, and render parameter of columns table column attributes; the title parameter refers to the text displayed in the column header; the dataIndex parameter refers to the path corresponding to the column data in the data item, and supports querying nested paths through arrays; the Key parameter is the attribute used by the React component library to identify the uniqueness of each component; the Render parameter is a function, and the render function returns a specific Input or select box, which is wrapped with a Form.Item form item. The name value of the Form.Item form item is set to the array format [field.name, custom name], and the first parameter value of [field.name, custom name] is filled in with the name of the field field passed in by the Form.List component, and the second parameter passes the name of the custom value to be displayed; Defining deleting data and passing in onClick method unit: used to define the operation display of deleting column data in the render function. When clicked, the remove function of the Form.List component is passed to the onClick click event method of the Table component.

[0032] This embodiment can completely use the Form.List component in combination with the Table component to dynamically add and delete form items in the table without maintaining more data changes and excessive table style processing.

[0033] An embodiment of the present invention further provides a computer device, Figure 2 is a schematic diagram of the structure of a computer device provided by an embodiment of the present invention; see the accompanying drawings Figure 2As shown, the computer device includes: an input device 23, an output device 24, a memory 22 and a processor 21; the memory 22 is used to store one or more programs; when the one or more programs are executed by the one or more processors 21, the one or more processors 21 implement the method for dynamically adding form items to a table based on antd as provided in the above embodiment; wherein the input device 23, the output device 24, the memory 22 and the processor 21 can be connected by a bus or other means, Figure 2 The example of connecting through bus is taken in the following.

[0034] The memory 22 is a readable and writable storage medium of a computing device, which can be used to store software programs and computer executable programs, such as program instructions corresponding to the method for dynamically adding form items to a table based on antd as described in an embodiment of the present invention; the memory 22 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and at least one application required for a function; the data storage area may store data created according to the use of the device, etc.; in addition, the memory 22 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device; in some instances, the memory 22 may further include a memory remotely arranged relative to the processor 21, and these remote memories may be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0035] The input device 23 may be used to receive input digital or character information, and to generate key signal input related to user settings and function control of the device; the output device 24 may include a display device such as a display screen.

[0036] The processor 21 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 22, that is, realizes the above-mentioned method of dynamically adding form items to a table based on antd.

[0037] The computer device provided above can be used to execute the method for dynamically adding form items to a table based on antd provided in the above embodiment, and has corresponding functions and beneficial effects.

[0038] The embodiment of the present invention also provides a storage medium containing computer executable instructions, which are used to execute the method of dynamically adding form items to a table based on antd as provided in the above embodiment when executed by a computer processor. The storage medium is any of various types of memory devices or storage devices, and the storage medium includes: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDRRAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media (such as hard disk or optical storage); registers or other similar types of memory elements, etc.; the storage medium may also include other types of memory or a combination thereof; in addition, the storage medium may be located in a first computer system in which the program is executed, or may be located in a different second computer system, which is connected to the first computer system via a network (such as the Internet); the second computer system may provide program instructions to the first computer for execution. The storage medium includes two or more storage media that can reside in different locations (for example, in different computer systems connected via a network). The storage medium can store program instructions (for example, specifically implemented as a computer program) that can be executed by one or more processors.

[0039] Of course, the storage medium containing computer executable instructions provided by an embodiment of the present invention is not limited to the method for dynamically adding form items to a table based on antd as described in the above embodiment, and can also execute related operations in the method for dynamically adding form items to a table based on antd provided in any embodiment of the present invention. So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.

[0040] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for dynamically adding form items to a table based on antd, characterized in that: The following steps are involved: S1. Use the Form.List component of Antd Design component to nest the Table component, and use the Table component as the main body of the loop; S2. Assign the fields attribute parameter of the Form.List component to the dataSource data source parameter of the Table component; S3. Define the parameter value of the columns table column attribute of the Table component, pass the parameter value of columns to the onClick event method of the Table component, and pass the remove column data function of the Form.List component to the onClick event method of the Table component; S4. Add a Button button definition under the Table component, and pass the onClick event method of the Table component to the add method of the Form.List component.

2. The method for dynamically adding form items to a table based on antd according to claim 1 is characterized in that: The parameter values ​​of the columns table column attribute of the definition Table component of the S3 step include: Define the title parameter, dataIndex parameter, key parameter, and render parameter of the columns table column attributes; Among them, the title parameter refers to the text displayed in the column header; The dataIndex parameter refers to the path corresponding to the column data in the data item, and supports querying nested paths through arrays; The Key parameter is the attribute used by the React component library to identify the uniqueness of each component; The Render parameter is a function. The render function returns a specific Input or select box, which is wrapped in a Form.Item form item. The name value of the Form.Item form item is set to the array format [field.name, custom name]. The first parameter value of [field.name, custom name] is filled in with the name of the field passed in by the Form.List component, and the second parameter passes the name of the custom value to be displayed.

3. The method for dynamically adding form items to a table based on antd according to claim 2 is characterized in that: The step S3 of passing the parameter value of columns into the onClick event method of the Table component, passing the remove function of the Form.List component into the onClick event method of the Table component, and passing the remove function of the Form.List component into the onClick event method of the Table component includes: The operation display of deleting column data is defined in the render function. When clicked, the remove function of the Form.List component is passed to the onClick click event method of the Table component.

4. The method for dynamically adding form items to a table based on antd according to claim 3 is characterized in that: The name of the field that the remove function passes into the onClick event method is Field.name.

5. The method for dynamically adding form items to a table based on antd according to claim 2 is characterized in that: In the case where only the dataIndex parameter has been set, the Key parameter is chosen to be ignored.

6. A system for dynamically adding form items to a table based on antd, executing a method for dynamically adding form items to a table based on antd as claimed in any one of claims 1 to 5, characterized in that: include: Form.List component nested Table component module: used to use Antd Design component's Form.List component to nest Table component, and use the Table component as the main body of the loop; The Form.List component assigns the Table component parameter module: used to assign the fields field attribute parameter of the Form.List component to the dataSource data source parameter of the Table component; The Remove function is passed into the onClick method module: it is used to define the parameter value of the columns table column attribute of the Table component, pass the columns parameter value into the onClick event method of the Table component, and pass the remove column data function of the Form.List component into the onClick event method of the Table component; The onClick method is passed into the add method module: it is used to add a Button button definition under the Table component, and pass the onClick event method of the Table component into the add method of the Form.List component.

7. The system for dynamically adding form items to a table based on antd according to claim 6 is characterized in that: The Remove function is passed into the onClick method module including: Define columns parameter value unit: used to define title parameter, dataIndex parameter, key parameter, and render parameter of columns table column attributes; the title parameter refers to the text displayed in the column header; the dataIndex parameter refers to the path corresponding to the column data in the data item, and supports querying nested paths through arrays; the Key parameter is the attribute used by the React component library to identify the uniqueness of each component; the Render parameter is a function, and the render function returns a specific Input or select box, which is wrapped in Form.Item form items. The name value of the Form.Item form item is set to the array format [field.name, custom name], and the first parameter value of [field.name, custom name] is filled in with the name of the field field passed in by the Form.List component, and the second parameter passes the name of the custom value to be displayed.

8. The system for dynamically adding form items to a table based on antd according to claim 6, characterized in that: The Remove function is passed into the onClick method module and also includes: Defining deleting data and passing in onClick method unit: used to define the operation display of deleting column data in the render function. When clicked, the remove function of the Form.List component is passed to the onClick click event method of the Table component.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method for dynamically adding form items to a table based on antd as described in any one of claims 1 to 5 are implemented.

10. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method for dynamically adding form items to a table based on antd as described in any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Method and device for processing table interaction based on React framework

    CN114296703A

  • Mobile terminal dynamic form generation method and device based on TableView

    CN114356334A

  • Low-code development method of configuration table component based on Ant Design

    CN115756467A

  • Method and system for knowledge-based filling and verification of complex forms

    US20090204881A1