2017-03-01 21 views
-1

我有两个意见:登录和菜单。如何在每次访问视图时调用onInit()?

场景:

登录 - >onInit() , onBeforeRendering() , onAfterRendering()被称为Menu.controller.js 并转到菜单视图。

注销 - >deleteData(); oRouter.navTo("Login", {}, true);返回 登录视图。

登录 - >onInit() , onBeforeRendering() , onAfterRendering() 不会被调用并进入菜单视图。

我试着我的菜单控制器连接到OnInit的具体路线,但它不工作:

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

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

回答

2

onInit只被调用一次。其Sapui5的生命周期方法。如果你想要一个函数,每次浏览时都会调用,然后使用onAfterRendering或onBeforeRendering。其他方面从路由匹配创建函数并调用该函数。

上面的路线匹配应该是这样的。

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

//现在做如下

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

我已经尝试了两件事,但他们不工作。如果我从路由匹配中调用该函数,它在注销时也会运行。如果我使用onAfterRendering或onBeforeRendering,则不会发生任何事情,因为页面不会重新渲染。 –

+0

那么这只是路由匹配时出现的问题,创建一个全局变量,并且一旦执行函数就将其赋值为真使该全局变量为假。 sap.ui.getCore()。urVariable = true;在onInit中执行此操作。现在,如果(sap.ui.getCore()。urVariable){//你的stuff.sap.ui.getCore()。urVariable = false; }将其设置为false。 –

相关问题