gpt4 book ai didi

javascript - 如何在每次进入 View 时调用 onInit()?

转载 作者:行者123 更新时间:2023-12-01 03:57:23 26 4
gpt4 key购买 nike

我有两个 View :登录和菜单。

场景:

Log in --> onInit() , onBeforeRendering() , onAfterRendering() gets called in Menu.controller.js and go to the Menu view.

Log out --> deleteData(); oRouter.navTo("Login", {}, true); Back to the login view.

Log in --> onInit() , onBeforeRendering() , onAfterRendering() doesn't get called and go to the Menu view.

我尝试将我的菜单 Controller 附加到 onInit 中的特定路由,但它不起作用:

function onInit(){
this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this._oRouter.attachRouteMatched(initMenu, this);
this.initMenu();
}

如何强制再次调用上述方法?我需要重新加载方法initMenu()这是在 onInit() 函数中正确接收菜单的。

最佳答案

onInit 仅被调用一次。其Sapui5的生命周期方法。如果您想要一个每次导航时都会被调用的函数,请使用 onAfterRendering 或 onBeforeRendering。否则创建函数并从路由匹配调用该函数。

above route match should be like this.

this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this._oRouter.attachRouteMatched(this.yurfunction, this);

//现在按如下操作

yurfunction(){ //now give call to you function from here }

关于javascript - 如何在每次进入 View 时调用 onInit()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42527773/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com