Form component persistent memory method based on DOM structure

By saving and restoring unique key values ​​generated by the component index and parent component hierarchical path in localStorage, the problem of data consistency and uniqueness of form components under complex DOM structures is solved, and the user experience and operation efficiency are improved.

CN118733593APending Publication Date: 2024-10-01CHINA TELECOM CLOUD TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410861673.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

In an environment with complex DOM structures and multiple form components, it is difficult for existing technologies to ensure the consistency and uniqueness of data, causing the form status to be lost after the page jumps or refreshes, affecting the user experience.

Method used

By saving the unique key of the form component in localStorage, a unique key value composed of the component index and the parent component hierarchical path is generated, and the Vue.js framework is used to serialize, save and restore the form state after user operation to ensure data consistency and Uniqueness.

Benefits of technology

It realizes the saving and restoration of the form component state after the user closes the browser or refreshes the page, improves user operation efficiency, enhances user experience, and ensures the consistency and uniqueness of data in complex DOM structures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733593A_ABST
    Figure CN118733593A_ABST
Patent Text Reader

Abstract

The invention discloses a form component persistent memory method based on a DOM (Document Object Model) structure. The method comprises the following steps: S1, writing data into a localStorage; s2, reading the data from the localStorage, and reading the data from the localStorage; s3, generating a component index and a parent component hierarchical path; and S4, generating a key. According to the method, the user experience can be improved, data loss can be prevented, meanwhile, the server pressure can be reduced, the data processing efficiency can be improved, the usability of software can be enhanced, although the scheme is based on Vue.js, the basic principle and the implementation mode of the method can be easily expanded to other front-end frames or native HTML and JavaScript environments, and extremely high technical flexibility is displayed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of IT technology, and in particular to a form component persistent memory method based on DOM structure. Background Art

[0002] The interactive experience of Web applications actually lies in the exquisite design and implementation of form components. Form components, such as select, input, textarea, option, etc., constitute the key nodes of interaction between users and systems. The status of these components often needs to be changed by users before subsequent operations can be performed. However, due to the statelessness of the Web, when users jump or refresh the page in the browser, the previous form status will be gone forever, causing users to re-enter or select, which undoubtedly brings inconvenience to users and affects the user experience.

[0003] In existing solutions, the state of each form component is saved independently, which makes it difficult to restore the form state in a complex DOM structure. In addition, since the state of each form component is saved independently, if there is a dependency between the states of multiple components, data inconsistency may occur when restoring the state. Finally, existing solutions usually require developers to manually generate a unique identifier for each form component, which not only increases the complexity of development, but also may cause data overwriting if the identifier is not unique.

[0004] Although the above methods can solve the problem of form state loss to a certain extent, they often have difficulty in ensuring data consistency and uniqueness when dealing with complex DOM structures and multiple form components. Summary of the invention

[0005] The purpose of this section is to summarize some aspects of embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the specification abstract and the invention title of this application to avoid blurring the purpose of this section, the specification abstract and the invention title, and such simplifications or omissions cannot be used to limit the scope of the present invention.

[0006] In view of the problems existing in the above-mentioned existing method for persistent memory of form components based on DOM structure, the present invention is proposed.

[0007] Therefore, the purpose of the present invention is to provide a form component persistent memory method based on a DOM structure, which is suitable for solving the problem of data consistency and uniqueness that is difficult to solve in an environment with a complex DOM structure and numerous form components.

[0008] In order to solve the above technical problems, the present invention provides the following technical solutions: a method for persistent memory of form components based on DOM structure, the method comprising the following steps:

[0009] S1: data is written to localStorage;

[0010] S2: read data from localStorage;

[0011] S3: Generate component index and parent component hierarchy path;

[0012] S4: Generate a key.

[0013] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, in which: in step S1, after the user performs a form operation, we serialize the user's operation results and the corresponding form component's unique key and save them in localStorage.

[0014] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, in which: in step S2, when the user visits the page again, we can read the user's operation results from localStorage through the previously saved key and restore the state of the form.

[0015] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, in which: in step S3, first find the position index of the current component in the node of the same level, that is, the component index, and then recursively traverse the parent node to generate the parent component hierarchical path.

[0016] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, in which: in step S4, the component index and the parent component hierarchical path are spliced ​​together to generate a unique key.

[0017] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, the core of the method is to use localStorage to read and write data, and at the same time, through the characteristics of the Vue.js framework, a unique key is generated for each form component. This key consists of two parts: the component index and the parent component hierarchy path.

[0018] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, the method is applicable to implementation in any front-end framework, including but not limited to Angular, React and JQuery, and is also applicable to the case where no front-end framework is used and only native HTML and JavaScript are used.

[0019] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, in which: in React, the same function is achieved through the component's state and props; in JQuery or native HTML and JavaScript, it is achieved through DOM attributes and methods.

[0020] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, the pseudo-code technology applicable to each framework is implemented as follows:

[0021]

[0022]

[0023]

[0024] As a preferred solution of the DOM structure-based form component persistent memory method described in the present invention, the method further includes the following implementation process:

[0025] ①: The user operates the form component to generate data;

[0026] ②: Get the index of the form component and the parent component hierarchy path through Vue.js to generate a unique key;

[0027] ③: Save the data and key to localStorage;

[0028] ④: When the user visits the page again, read the data from localStorage through the key and restore the state of the form component;

[0029] ⑤: If the user makes changes to the form component, repeat the above process.

[0030] Beneficial effects of the present invention: The present invention generates a unique key value for each form component through the DOM structure. The key value consists of a component index and a parent component hierarchical path. This ensures that within the same page, regardless of whether the form components are at the same DOM hierarchy, their key values ​​are unique. The present invention uses localStorage for persistent data storage. After the user performs a form operation, the user's operation result and the corresponding unique key value of the form component are serialized and saved in localStorage, so that even after the user closes the browser or refreshes the page, the state of the form component can still be saved and restored;

[0031] When the user visits the page again, the present invention can read the user's operation results from localStorage through the previously saved key value and restore the state of the form, which greatly improves the user's operation efficiency and enhances the user experience. If the user changes the form component, the present technology can update the value in localStorage in real time to ensure the real-time and accuracy of the data. The present invention successfully handles complex DOM structures and multiple form components by generating a parent component hierarchical path, thereby ensuring the consistency and uniqueness of the data. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. 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 creative work. Among them:

[0033] Figure 1 A schematic diagram of a flow chart of a method for persistent memory of form components based on a DOM structure proposed by the present invention;

[0034] Figure 2 A timing diagram of a DOM structure-based form component persistent memory method proposed by the present invention. DETAILED DESCRIPTION

[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.

[0036] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0037] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.

[0038] Secondly, the present invention is described in detail with reference to the schematic diagram. When describing the embodiments of the present invention in detail, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.

[0039] Example

[0040] Reference Figure 1-Figure 2 , as an embodiment of the present invention, provides a method for persistent memory of form components based on DOM structure, the method comprising the following steps:

[0041] S1: data is written to localStorage;

[0042] In step S1, after the user performs a form operation, we serialize the user's operation result and the unique key of the corresponding form component and save them to localStorage; the code is as follows:

[0043] localStorage.setItem(key,JSON.stringify(value));

[0044] S2: read data from localStorage;

[0045] In step S2, when the user visits the page again, we can read the user's operation results from localStorage through the previously saved key and restore the state of the form; the code is as follows:

[0046] const v=localStorage.getItem(key);

[0047] S3: Generate component index and parent component hierarchy path;

[0048] In step S3, first find the position index of the current component in the node of the same level, that is, the component index; the code is as follows:

[0049] let index=this.parent.children.findIndex(i==>i===this);

[0050] Then recursively traverse the parent node to generate the parent component hierarchy path; the code is as follows:

[0051]

[0052] S4: Generate key;

[0053] In step S4, the component index and the parent component hierarchy path are concatenated to generate a unique key; the code is as follows:

[0054] ${index}-${path}.

[0055] The core of the method is to use localStorage to read and write data. At the same time, through the characteristics of the Vue.js framework, a unique key is generated for each form component. This key consists of two parts: the component index and the parent component hierarchy path.

[0056] The method is applicable to implementation in any front-end framework, including but not limited to Angular, React, and JQuery. It is also applicable when no front-end framework is used and only native HTML and JavaScript are used.

[0057] In React, the same functionality is achieved through component state and props; in JQuery or native HTML and JavaScript, it is achieved through DOM attributes and methods.

[0058] The key steps, i.e. generating unique key values, persistent storage, data recovery, and dynamic updates, can all be implemented in other front-end frameworks or native HTML and JavaScript. For example, we can use Angular's component lifecycle hook function to get the component index and parent component hierarchy path, and then generate a unique key value; in React, we can use the component's state and props to achieve the same function; in JQuery or native HTML and JavaScript, we can use DOM attributes and methods to achieve it.

[0059] Therefore, this technical solution is not limited to Vue.js, but has wide applicability. No matter in which front-end framework or native HTML and JavaScript, as long as the main steps of this technical solution are followed, the persistent memory function of the form component can be realized, thereby improving the user experience and the usability of the software.

[0060] Pseudocode technical implementation applicable to each framework:

[0061]

[0062]

[0063] The method also includes the following implementation process:

[0064] ①: The user operates the form component to generate data;

[0065] ②: Get the index of the form component and the parent component hierarchy path through Vue.js to generate a unique key;

[0066] ③: Save the data and key to localStorage;

[0067] ④: When the user visits the page again, read the data from localStorage through the key and restore the state of the form component;

[0068] ⑤: If the user changes the form component, repeat the above process;

[0069] Through the above process, the persistent memory function of the form component can be realized, which can improve the user experience and the usability of the software. This process also provides new ideas for Web development and helps promote the development of Web technology.

[0070] During use, the present invention generates a unique key value for each form component through the DOM structure. The key value consists of two parts: the component index and the parent component hierarchy path. It is ensured that within the same page, regardless of whether the form components are at the same DOM hierarchy, their key values ​​are unique. The present invention uses localStorage for persistent storage of data. After the user performs a form operation, the user's operation result and the corresponding unique key value of the form component are serialized and saved in localStorage, so that even after the user closes the browser or refreshes the page, the state of the form component can still be saved and restored;

[0071] When the user visits the page again, the present invention can read the user's operation results from localStorage through the previously saved key value and restore the state of the form, which greatly improves the user's operation efficiency and enhances the user experience. If the user changes the form component, the present technology can update the value in localStorage in real time to ensure the real-time and accuracy of the data. The present invention successfully handles complex DOM structures and multiple form components by generating a parent component hierarchical path, thereby ensuring the consistency and uniqueness of the data.

[0072] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.

Claims

1. A method for persistent memory of form components based on DOM structure, characterized in that: The method comprises the following steps: S1: data is written to localStorage; S2: read data from localStorage; S3: Generate component index and parent component hierarchy path; S4: Generate a key.

2. According to the DOM structure-based form component persistent memory method of claim 1, it is characterized by: In step S1, after the user performs a form operation, we serialize the user's operation result and the unique key of the corresponding form component and save them in localStorage.

3. According to the DOM structure-based form component persistent memory method of claim 1, it is characterized by: In step S2, when the user visits the page again, we can read the user's operation results from localStorage through the previously saved key and restore the state of the form.

4. The method for persistent memory of form components based on DOM structure according to claim 1, characterized in that: In step S3, first find the position index of the current component in the node at the same level, that is, the component index, and then recursively traverse the parent node to generate the parent component hierarchical path.

5. The method for persistent memory of form components based on DOM structure according to claim 4 is characterized in that: In step S4, the component index and the parent component hierarchy path are concatenated to generate a unique key.

6. The method for persistent memory of form components based on DOM structure according to claim 1, characterized in that: The core of the method is to use localStorage to read and write data, and at the same time, through the characteristics of the Vue.js framework, a unique key is generated for each form component. This key consists of two parts: the component index and the parent component hierarchy path.

7. The method for persistent memory of form components based on DOM structure according to claim 1, characterized in that: The method is applicable to implementation in any front-end framework, including but not limited to Angular, React, and JQuery, and is also applicable to implementation without using any front-end framework and using only native HTML and JavaScript.

8. The method for persistent memory of form components based on DOM structure according to claim 7, characterized in that: In React, the same functionality is achieved through component state and props; in JQuery or native HTML and JavaScript, it is achieved through DOM attributes and methods.

9. The method for persistent memory of form components based on DOM structure according to claim 7, characterized in that: Pseudocode technical implementation applicable to each framework: / / Generate a unique key for each form element function generateUniqueKey(formElement){ / / Generate key logic, which can be based on element attributes such as id, name, position, etc.} / / Save form data to localStorage function saveFormDataToLocalStorage(formElement){ / / Get the value of the form element let value=formElement.value; / / Generate a unique key let key=generateUniqueKey(formElement); / / Store the value in localStorage localStorage.setItem(key,value); } / / Restore form data from localStorage function restoreFormDataFromLocalStorage(formElement){ / / Generate a unique key let key=generateUniqueKey(formElement); / / Get the value from localStorage let value=localStorage.getItem(key); / / If the value exists, restore it to the form element if(value){ formElement.value = value; } } / / Listen for the change event of the form element for each formElement in formElements{ formElement.addEventListener('change',function(){ / / When the value of the form element changes, save it to localStorage saveFormDataToLocalStorage(formElement); 10. The method for persistent memory of form components based on DOM structure according to claim 1, characterized in that: The method also includes the following implementation process: ①: The user operates the form component to generate data; ②: Get the index of the form component and the parent component hierarchy path through Vue.js to generate a unique key; ③: Save the data and key to localStorage; ④: When the user visits the page again, read the data from localStorage through the key and restore the state of the form component; ⑤: If the user makes changes to the form component, repeat the above process.

Citation Information

Patent Citations

  • Intelligent record form filling method

    CN108345578A

  • Page component display method and device

    CN110069734A

  • Low-code form opening method, system and device based on configuration

    CN114035773A