콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
2358 화면

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?



아바타
취소
베스트 답변

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

아바타
취소
관련 게시물 답글 화면 활동
2
7월 24
5233
0
1월 24
1967
0
9월 23
1748
1
1월 25
3909
1
6월 24
4615