2016-11-12 49 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; 
} 
相关问题