2016-11-12 46 views
0

我在我的UI5應用程序中使用echarts,所以我需要等待dom準備好然後執行_onObjectMatched,但是在第一次加載時,如果我將它放在onInit中,則會觸發_onObjectMatched,但它在onAfterRendering中不起作用。我把一個日誌放在了AfterRendering之後,所以我很確定onAfterRendering被執行了,之後的_onObjectMatched調用OK。順便說一句,我正在建立一個主 - 詳細頁面。爲什麼如果將attachPatternMatched放入onAfterRendering中,它將無法在第一次加載中工作?

onInit : function() { 
    this.getRouter().getRoute("object").attachPatternMatched(this._onObjectMatched, this); 
} 

onAfterRendering: function() { 
    this.getRouter().getRoute("object").attachPatternMatched(this._onObjectMatched, this); 
} 

getRouter : function() { 
    return sap.ui.core.UIComponent.getRouterFor(this); 
}, 

回答

2

該路線在onInit()之後但在onAfterRendering()之前匹配。所以,如果你附加你的事件處理程序onAfterRendering()你太遲了,錯過了事件。

如果您的echart尚未準備好,我會建議您在onInit()附上您的處理程序並將路徑信息保存在控制器中。 在您的echart初始化後更新您的視圖後使用該信息。

onAfterRendering:function(){ 
    //init charts 
    this._chartReady = true; 
    this._updateViewFromRoute(); 
}, 
onBeforeRendering:function(){ 
    this._chartReady = false; 
}, 
_onObjectMatched:function(oEvent){ 
    //Save Args 
    this._routerArgs = oEvent.getParameter("arguments"); 
    this._updateViewFromRoute(); 
}, 
_updateViewFromRoute:function(){ 
    if(!this._chartReady) return; 
    if(!this._routerArgs) return; 
    //do something with this._routerArgs 
    this._routerArgs = null; 
} 
相關問題