我有兩個意見:登錄和菜單。如何在每次訪問視圖時調用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()
才能正確接收菜單。
我已經嘗試了兩件事,但他們不工作。如果我從路由匹配中調用該函數,它在註銷時也會運行。如果我使用onAfterRendering或onBeforeRendering,則不會發生任何事情,因爲頁面不會重新渲染。 –
那麼這只是路由匹配時出現的問題,創建一個全局變量,並且一旦執行函數就將其賦值爲真使該全局變量爲假。 sap.ui.getCore()。urVariable = true;在onInit中執行此操作。現在,如果(sap.ui.getCore()。urVariable){//你的stuff.sap.ui.getCore()。urVariable = false; }將其設置爲false。 –