Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2097 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
čvc 24
4781
0
led 24
1445
0
zář 23
1530
1
led 25
3544
1
čvn 24
3998