Sapui5 如何在每次查看页面时执行代码

Sapui5 如何在每次查看页面时执行代码,sapui5,Sapui5,每次查看页面时(每次通过splitApp.toDetail或splitApp.backDetail调用页面时),我都在搜索执行代码的模式(在我的示例中,是从服务器检索数据以可视化)。我怎么做 另外,渲染前的和渲染后的仅第一次执行。我在目标视图中使用onBeforeShow onBeforeShow : function(evt) { // gets called everytime the user // navigates to this view }, 这是一个函数,在导

每次查看页面时(每次通过
splitApp.toDetail
splitApp.backDetail
调用页面时),我都在搜索执行代码的模式(在我的示例中,是从服务器检索数据以可视化)。我怎么做


另外,渲染前的
和渲染后的
仅第一次执行。

我在目标视图中使用
onBeforeShow

onBeforeShow : function(evt) {
    // gets called everytime the user 
    // navigates to this view
},

这是一个函数,在导航的情况下,由a在其子级上激发。它记录在中。

有一个解决方案供您使用。每次触发导航时,都会出现一个名为“路由匹配”的事件。您可以在详细信息页面中附加事件

onInit:function(){
this.\u oRouter=sap.ui.core.UIComponent.getRouterFor(this);
this.\u oRouter.attachRouteMatched(this.handleRouteMatched,this);
},
HandlerRouteMatched:功能(evt){
//检查详细信息页面是否匹配。
if(evt.getParameter(“名称”)!=“详细信息”){
返回;
//您可以在这里编写代码,以便在每次调用详细信息页面时运行。
}

如果使用布线,则另一版本的艾伦代码:

 onInit : function () {
   this._oRouter = sap.ui.core.UIComponent.getRouterFor(this);
   this._oRouter.getRoute("detail").attachMatched(this.handleRouteMatched, this);
},

  handleRouteMatched : function (evt) {
    //You code here to run every time when your detail page is called.
  }

您是否在目标视图中插入了
onBeforeShow
。表示在
splitApp.toDetail()中的目标视图中
?是的,我将
onbeforeredering
替换为
onBeforeShow
。现在该代码从未执行过。好的,我再试了一次,它可以工作。在中,它被描述为手动订阅此事件。您可以尝试此操作,否则您可以向我们显示更多代码(拆分应用程序、视图)。但是在您的应用程序上运行时没有注册
beforeShow
事件?我只将
onbeforeredering
替换为
onBeforeShow
,但不通过
this注册视图。addEventDelegate({onBeforeShow:function(evt){…
I注册到onInit…它工作…
//INIT onInit onInit:function(){//为beforeShow事件注册this.getView().addEventDelegate({//未将控制器添加为委托,以避免控制器函数与beforeShow上的事件具有类似的名称:jQuery.proxy(函数(evt){this.onBeforeShow(evt);},this)}),onBeforeShow:function(evt){alert(“onBeforeShow”);},
这是否回答了您的问题?>仅第一次执行
onbeforeredering
onAfterRendering
请参见