每次移动到视图时如何调用 onInit()? [英] How do I invoke onInit() every time I move to a view?

查看:35
本文介绍了每次移动到视图时如何调用 onInit()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图 (View1),它设置了它导航到的视图 (View2) 所需的变量.用户可以返回到 View1 并选择一个按钮来更改变量,然后单击提交再次转到 View2.

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 在其 onInit() 方法中调用 OData 服务,并将此变量用作调用的一部分.

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

如何确保每次导航到 View2 时始终执行此功能?我尝试执行 .destroy() 但这会删除 ID 并且它不能被 View1 重用.

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.

推荐答案

两个视图是否都存在于 sap.m.NavContainer 或 sap.m.App(派生自它)中?然后您可以使用 NavContainer 在每个子项(在您的情况下为视图)上触发的beforeShow"事件,请参见https://openui5.hana.ondemand.com/#docs/api/symbols/sap.m.NavContainerChild.html(您将在视图上调用 addEventDelegate(...))

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.

但是,还要考虑是否可以在您的情况下使用数据绑定.在最简单的情况下,View 1 只需要更改绑定上下文,ODataModel 会自动更新 View 2 的数据.

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.

这篇关于每次移动到视图时如何调用 onInit()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆