How do I invoke onInit() every time I move to a vi

2020-04-18 08:31发布

I have a view (View1) which sets a variable needed by the view (View2) it navigates to. The user can go back to View1 and select a button to change the variable, then click submit to go to View2 again.

View2 calls an OData service in its onInit() method, and uses this variable as part of the call.

How do I ensure View2 is always performing this function every time it is navigated to? I tried doing .destroy() but that removes the ID and it can't be reused by View1.

标签: sapui5
1条回答
闹够了就滚
2楼-- · 2020-04-18 09:08

Are both views living inside a sap.m.NavContainer or sap.m.App (which derives from it)? Then you can use the "beforeShow" event that the NavContainer fires on each child (in your case the View), see https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.NavContainerChild.html (you would call the addEventDelegate(...) on the View)

You are not using the Routing, right? I think it would provide sufficient hooks.

However, also think about whether data binding could be used in your situation. In the most simple case, View 1 would only need to change the binding context and the ODataModel would update the data for View 2 automatically.

查看更多
登录 后发表回答