Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
2117 Näkymät

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?



Avatar
Hylkää
Paras vastaus

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

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
heinäk. 24
4831
0
tammik. 24
1465
0
syysk. 23
1537
1
tammik. 25
3561
1
kesäk. 24
4047