Implementation method and device of list sorting component, equipment and storage medium
By introducing React DnD technology on the React framework, creating drag-and-drop list sorting components and supporting flexible configuration of target parameters, the problem of insufficient flexibility of list sorting components in the existing technology is solved, and efficient and flexible list sorting functions are realized.
Patent Information
- Application Number
- CN202411191523.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-28
- Publication Date
- 2024-12-06
AI Technical Summary
The existing list sorting components have poor flexibility and are difficult to meet component design needs in different scenarios.
By introducing the React framework and React DnD technology, a drag-and-drop list sorting component is created, which supports developers to flexibly configure target parameters, including list item identification, index, content and callback functions, to achieve flexibility in list sorting and user-friendly drag-and-down Reveal interactive experience.
It improves the development flexibility and maintainability of list sorting components, meets the component design needs in different scenarios, reduces the amount of code writing, and provides efficient drag-and-drop sorting functions.
Smart Images

Figure CN119088388A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software development, and in particular to an implementation method, device, equipment and storage medium of a list sorting component. Background Art
[0002] In the field of software development, when using the React framework for development, it is often necessary to implement a draggable list sorting function. There are already some libraries, such as react-beautiful-dnd and react-sortablejs, that provide some list sorting solutions based on drag and drop.
[0003] However, these libraries have poor flexibility and are difficult to meet component design requirements in different scenarios. Summary of the invention
[0004] In view of this, a method, apparatus, device and storage medium for implementing a list sorting component are provided to solve the problem that the existing implementation scheme of the list sorting component has poor flexibility and is difficult to meet the component design requirements in different scenarios.
[0005] The present invention adopts the following technical solution:
[0006] In a first aspect, the present invention provides a method for implementing a list sorting component, comprising:
[0007] A React framework is introduced, and a React component is created on the React framework; the React component is used as a list item of a list sorting component;
[0008] React DnD technology is introduced to expand the function of the React component, so that the React component accepts target parameters;
[0009] Insert the React component where the React component is used, and configure the parameter content of the target parameter of the React component.
[0010] Optionally, the target parameters include: list item identifier, list item index, list item content and callback function.
[0011] Optionally, the callback function is onMove;
[0012] The onMove function is used to update the column sorting of the list based on the current position and original position of the dragged element when the corresponding list item is dragged.
[0013] Optionally, after inserting the React component at the place where the React component is used and configuring the parameter content of the target parameter of the React component, the implementation method of the list sorting component of the present invention further includes:
[0014] In response to the modification operation of the developer, the parameter content corresponding to the target parameter is modified.
[0015] In a second aspect, the present invention provides an implementation device of a list sorting component, comprising:
[0016] Create a module for introducing a React framework, and create a React component on the React framework; the React component is used as a list item of a list sorting component;
[0017] An extension module, used for introducing the React DnD technology to expand the function of the React component, so that the React component accepts target parameters;
[0018] The configuration module is used to insert the React component where the React component is used, and configure the parameter content of the target parameter of the React component.
[0019] Optionally, the target parameters include: list item identifier, list item index, list item content and callback function.
[0020] Optionally, the callback function is onMove;
[0021] The onMove function is used to update the column sorting of the list based on the current position and original position of the dragged element when the corresponding list item is dragged.
[0022] In a third aspect, the present invention provides a computer device, comprising:
[0023] at least one processor; and,
[0024] a memory communicatively connected to the at least one processor; wherein,
[0025] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to implement the implementation method of the list sorting component as described above.
[0026] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the method for implementing the list sorting component as described above.
[0027] The present invention adopts the above technical scheme, a method for implementing a list sorting component, including: introducing a React framework, creating a React component on the React framework; the React component is used as a list item of the list sorting component; introducing the React DnD technology to expand the function of the React component, so that the React component accepts the target parameter; inserting the React component where the React component is used, and configuring the parameter content of the target parameter of the React component. Based on this, since the present invention supports developers to flexibly configure the parameter content of the target parameter, the present invention improves the flexibility of list sorting component development and meets the component design requirements in different scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 It is a flowchart of a method for implementing a list sorting component provided by an embodiment of the present invention;
[0030] Figure 2 It is a structural diagram of an implementation device of a list sorting component provided by an embodiment of the present invention;
[0031] Figure 3 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0032] To make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.
[0033] Example
[0034] Figure 1 It is a flowchart of a method for implementing a list sorting component provided by an embodiment of the present invention.
[0035] like Figure 1 As shown, the implementation method of this list sorting component includes:
[0036] Step 101: Introduce the React framework and create a React component on the React framework; the React component is used as a list item of the list sorting component.
[0037] Specifically, React is a JavaScript library for building user interfaces. The React framework is used as a view layer in the present invention, which can simplify developers' operations on page elements, allowing developers to build efficient and maintainable front-end applications.
[0038] The list sorting component of the present invention may specifically be a draggable list sorting component, and the React component may specifically be a part of the draggable list sorting component—a list item in a sortable list.
[0039] Step 102: Introduce React DnD technology to expand the functionality of the React component so that the React component accepts target parameters.
[0040] Specifically, React DnD (Drag and Drop for React, react-dnd) is a React high-order component library created by Dan Abramov, the core author of React and Redux, which provides a set of tools for building draggable and droppable components. The main purpose of this library is to enable developers to easily implement drag and drop functionality in React applications without having to deal with complex DOM operations and event monitoring in depth.
[0041] Step 103: Insert the React component where the React component is used, and configure the parameter content of the target parameter of the React component.
[0042] Specifically, developers can configure the parameter content of the target parameter according to actual needs, configure different list items and sorting rules, and then implement flexible list sorting functions. Specifically, developers can define the display text and icon information of each list item according to actual needs, and specify sorting rules.
[0043] Subsequently, the system can generate corresponding interface elements according to the configuration information, and display the configuration information as a draggable list. Then, through the react-dnd technology, the dragging function of the list items is realized, and the sorting is adjusted according to the position of the user's drag. This enables the present invention to provide a user-friendly drag interaction experience.
[0044] The embodiment of the present invention adopts the above technical solution, by introducing the React framework, creating a React component on the React framework; the React component is used as a list item of the list sorting component; the React DnD technology is introduced to expand the function of the React component, so that the React component accepts the target parameter; the React component is inserted where the React component is used, and the parameter content of the target parameter of the React component is configured. Based on this, since the present invention supports developers to flexibly configure the parameter content of the target parameter, the present invention improves the flexibility of list sorting component development and meets the component design requirements in different scenarios.
[0045] In the embodiment of the present invention, the target parameters may include: a list item identifier, a list item index, a list item content, and a callback function.
[0046] Specifically, the list item identifier is the key in React. In React, the key attribute is a special string attribute that is used to give an element a stable identity, thereby helping React identify which items have changed, been added, or been removed. This is especially important when rendering lists (such as using the map() method to traverse an array and return multiple elements), because the order of the list items may change, or the list items themselves may be added, deleted, or updated.
[0047] When you use react-dnd to handle drag list items, the concept of key also applies. Each list item should have a unique key attribute so that React can update and render the UI more efficiently, and react-dnd can correctly track the elements during the drag process.
[0048] In a drag scenario, the key is usually a unique identifier associated with the list item data, such as an ID, which exists when the list item is created and remains unchanged during the life cycle of the list item. In this way, even if the position of the list item changes due to the drag operation, React can accurately identify each list item through the key and update the DOM (Document Object Model) accordingly.
[0049] The index of a list item is called index. In React, index usually refers to the ordinal position of each element in the list (counting starts from 0).
[0050] The list item content is Children. Children is a special attribute in the React component, which contains all the content within the component tag.
[0051] In the prior art, in order to implement a draggable list sorting function, it is necessary to listen to the corresponding drag events through the HTML Drag and Drop API, and developers are required to handle the drag relationship between multiple DOM elements. The details are cumbersome and complicated, difficult to maintain, and not conducive to expansion.
[0052] Based on this, in order to reduce the amount of code writing for list sorting components, improve development efficiency, and also improve the maintainability and extensibility of the code, in an embodiment of the present invention, the callback function can be onMove; onMove is used to update the column sorting of the list based on the current position and original position of the dragged element when the corresponding list item is dragged.
[0053] Specifically, the callback function onMove is used to handle the position exchange during dragging. Specifically, onMove is used to use react-dnd to process the position information generated by the dragged element when the corresponding list item is dragged, compare the current position and the original position of the dragged element, and update the column sorting of the list through onMove. Based on this, since react-dnd is used to process the position information generated by the dragged element and compare the current position and the original position of the dragged element, it can be seen that in the embodiment of the present invention, only the position information of the current dragged element needs to be processed, so that the present invention can reduce the amount of code writing for the list sorting component, improve development efficiency, and also improve the maintainability and extensibility of the code.
[0054] In the embodiment of the present invention, after inserting the React component where the React component is used and configuring the parameter content of the target parameter of the React component, the implementation method of the list sorting component of the present invention may further include:
[0055] In response to the modification operation of the developer, the parameter content of the corresponding target parameter is modified.
[0056] In this way, by providing an interface, developers are allowed to dynamically modify the parameter content of the target parameter, thereby realizing a flexible list sorting function.
[0057] Based on a general inventive concept, the present invention also provides an implementation device of a list sorting component. Figure 2 FIG. 1 is a schematic diagram of a structure of an implementation device of a list sorting component provided by an embodiment of the present invention. Figure 2 As shown, the implementation device of this list sorting component includes:
[0058] Create module 21 to introduce the React framework and create a React component on the React framework; the React component is used as a list item of the list sorting component.
[0059] The extension module 22 is used to introduce the React DnD technology to expand the function of the React component so that the React component accepts the target parameter.
[0060] The configuration module 23 is used to insert the React component where the React component is used, and configure the parameter content of the target parameter of the React component.
[0061] Optionally, the target parameters include: list item identifier, list item index, list item content and callback function.
[0062] Optionally, the callback function is onMove;
[0063] The onMove function is used to update the column sorting of the list based on the current position and original position of the dragged element when the corresponding list item is dragged.
[0064] Optionally, the implementation device of the list sorting component of the present invention may further include:
[0065] The modification module is used to modify the parameter content corresponding to the target parameter in response to the modification operation of the developer.
[0066] Based on a general inventive concept, the present invention also provides a computer device. Figure 3 Schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Figure 3 As shown, the computer device 300 includes:
[0067] at least one processor 310; and,
[0068] A memory 330 is communicatively connected to at least one processor 310; wherein,
[0069] The memory 330 stores instructions 320 that can be executed by at least one processor 310. The instructions 320 are executed by at least one processor 310 so that the at least one processor 310 can implement the above-mentioned implementation method of the list sorting component.
[0070] Based on a general inventive concept, the present invention further provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the implementation method of the above-mentioned list sorting component is implemented.
[0071] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.
[0072] It should be noted that, in the description of the present invention, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.
[0073] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code comprising one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present invention includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present invention belong.
[0074] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0075] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0076] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0077] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0078] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0079] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A method for implementing a list sorting component, characterized in that: include: Introduce the React framework and create a React component on the React framework; The React component is used as a list item of the list sorting component; React DnD technology is introduced to expand the function of the React component, so that the React component accepts target parameters; Insert the React component where the React component is used, and configure the parameter content of the target parameter of the React component.
2. The method for implementing the list sorting component according to claim 1, characterized in that: The target parameters include: list item identifier, list item index, list item content and callback function.
3. The method for implementing the list sorting component according to claim 2, characterized in that: The callback function is onMove; The onMove function is used to update the column sorting of the list based on the current position and original position of the dragged element when the corresponding list item is dragged.
4. The method for implementing the list sorting component according to claim 1, characterized in that: After inserting the React component where the React component is used and configuring the parameter content of the target parameter of the React component, the method further includes: In response to the modification operation of the developer, the parameter content corresponding to the target parameter is modified.
5. A device for implementing a list sorting component, characterized in that: include: Create a module for introducing a React framework, and create a React component on the React framework; the React component is used as a list item of a list sorting component; An extension module, used for introducing the React DnD technology to expand the function of the React component, so that the React component accepts target parameters; The configuration module is used to insert the React component where the React component is used, and configure the parameter content of the target parameter of the React component.
6. The implementation device of the list sorting component according to claim 5, characterized in that: The target parameters include: list item identifier, list item index, list item content and callback function.
7. The implementation device of the list sorting component according to claim 6, characterized in that: The callback function is onMove; The onMove function is used to update the column sorting of the list based on the current position and original position of the dragged element when the corresponding list item is dragged.
8. A computer device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to implement the implementation method of the list sorting component according to any one of claims 1 to 4.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the implementation method of the list sorting component according to any one of claims 1 to 4 is implemented.
