查看休假事件 [英] Event for view leave
问题描述
我在 SAPUI5 应用程序中为视图声明了一个控制器.现在我想在用户离开视图时执行任务.
I declared a controller for a view in my SAPUI5 application. Now I want to perform tasks when the view is left by the user.
已经可以将回调函数添加到 attachRoutePatternMatched
以在用户导航视图时执行任务,现在我需要一个等效的函数来处理视图的离开.我使用 SplitContainer
作为父容器
There is already a possibility to add a callback function to attachRoutePatternMatched
to perform tasks when the view is navigated by the user now I need a equivalent function to handle a leave of the view. I use a SplitContainer
as parent container
onInit: function() {
this._oRouter = this.getOwnerComponent().getRouter();
this._oRouter.attachRoutePatternMatched(this._routePatternMatched, this);
},
_routePatternMatched: function(oEvent) {
var that = this;
var sRouteTargetName = oEvent.getParameter("name");
if (sRouteTargetName === "myView") {
// perform tasks if the view is opened by the user
}
},
推荐答案
您可以使用 BeforeHide
委托在 NavContainer child 上,这通常是视图:
You can achieve this with BeforeHide
delegate on the NavContainer child which is often the view:
onInit: function() {
this._navDelegate = { onBeforeHide: this.onBeforeLeave };
this.getView()/*<-- navContainerChild*/.addEventDelegate(this._navDelegate, this);
},
onBeforeLeaving: function(event) {
// ... do something
},
onExit: function() {
// detach events, delegates, and references to avoid memory leak
this.getView().removeEventDelegate(this._navDelegate);
this._navDelegate = null;
},
示例: https://embed.plnkr.co/wp6yes?show=controller%2FNext.controller.js,preview%23next
- API 参考:
NavContainerChild
- API 参考:
sap.ui.core.Element#addEventDelegate
对于其他导航相关事件,请参阅https://stackoverflow.com/a/55649563中提到的文档主题
For other navigation related events, see documentation topics mentioned in https://stackoverflow.com/a/55649563
这篇关于查看休假事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!