Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2215 Widoki

I created a "ir.actions.client" component just like: (just simple example, pls ignore the coding errors, just help to explain my question)


class TestComponent extends Component {
static template = xml`
    
    
        
    
`;
   setup() {...}
   this.params_test = useState("");
   this.results = useState([]); 
   dosomething(){  ...  }
}
TestComponent.template = "test_template";
registry.category("actions").add("testcomponent", TestComponent);


from this page, I submit parameter and get the values from backend, and render the "results" to the page. then I select on record of results and click it to its detailed page(actually it's in another module), after that when I click back to the "TestComponent" page, all results disappeared, also without the parameter i submitted --- it's just a initial page.

My question, how to store the "TestComponent" page state when go to another page, and can find them when back to this page?



Awatar
Odrzuć
Najlepsza odpowiedź

Hi,

To address this issue, you can store your data in the cache using the following steps:

Step 1:
You can utilize the onWillDestroy hook to save the current page's values when you navigate to another page.

Step 2:
Inside the onWillDestroy hook, set the cache values.

Step 3:
When returning to the previous page, retrieve the values from the cache.

Here's an example of how to implement this:
import { onMounted, Component, onWillDestroy } from "@odoo/owl";

class TestComponent extends Component {
    setup() {
        onWillDestroy(async () => {
            // Prepare values for caching
            const values = {
                time: this.time,
                content: 'Demo Content'
            };
           
            // Store values in local storage for potential resumption
            await browser.localStorage.setItem('AnalyticCacheResume', JSON.stringify(values));
        });

        onMounted(async () => {
            // Retrieve cached values from local storage for initial timer setup
            const values = JSON.parse(browser.localStorage.getItem('AnalyticCache') || '{}');
           
            // Log the retrieved values to the console
            console.log(values);

            // If you need to remove the cached data, you can use:
            browser.localStorage.removeItem('AnalyticCacheResume');
        });
    }
}

Note:-Change the owl hooks according to your use case.Please refer the below link to know more about owl hooks

Owl Hooks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lip 24
4994
0
sty 24
1632
0
wrz 23
1620
1
sty 25
3698
1
cze 24
4280