[英]Event Handler for Launcpad Header Back Button
I need to overwrite the event of Launchpad Header Back Button in certain cases.在某些情况下,我需要覆盖 Launchpad Header Back Button 的事件。 I tried lots of things like:我尝试了很多事情,例如:
try { sap.ui.getCore().byId("backBtn").attachPress(this, function(oEvent) { oEvent.preventDefault(); }.bind(this)); } catch (err) { console.log(err); }
or或者
$('body').mousedown(function(e) { var oTarget = $(e.target); console.log(oTarget[0].offsetParent.id); console.log(oTarget[0]); if (oTarget[0].offsetParent.id === "backBtn") { console.log("prevent"); e.preventDefault(); e.stopPropagation(); return false; } }.bind(this));
In these codes I just tried to prevent the navi, getting back.在这些代码中,我只是试图阻止导航返回。 Didn't work.没用。 I want to navigate to certain views in certain cases.在某些情况下,我想导航到某些视图。 For example:例如:
if user is in view 3 -> click Launchpad Back Button -> navigate to view 1 (not the previous navigation target)如果用户在视图 3 -> 单击启动板后退按钮 -> 导航到视图 1(不是上一个导航目标)
But I couldn't stop navigation mechanism to go back to previous target.但我无法停止导航机制以返回上一个目标。
I'd appreciate any help or ideas.我将不胜感激任何帮助或想法。
First you need to register the ShellUIService in your manifest.json 首先,您需要在manifest.json中注册ShellUIService。
In manifest.json under sap.ui5: 在sap.ui5下的manifest.json中:
...
"sap.ui5": {
...
"services": {
"ShellUIService": {
"factoryName": "sap.ushell.ui5service.ShellUIService"
}
}
...
}
...
then you can override the default behavior in your controller (or from the component) 那么您可以在控制器中(或从组件中)覆盖默认行为
this.getOwnerComponent().getService("ShellUIService").then(function(oShellService) {
oShellService.setBackNavigation(function() {
//either do nothing to disable it, or add your own back nav logic
})
}) })
I've had trouble preventing the default Fiori shell(launchpad) actions in the past myself. 我过去无法阻止默认的Fiori shell(launchpad)操作。 A different approach might be to use sap.ui.core.routing's HashChanger and/or the Router (presumably you are already using a router in your app). 另一种方法可能是使用sap.ui.core.routing的HashChanger和/或路由器 (假定您已经在应用程序中使用了路由器)。
It's not incredibly elegant, but you could use the HashChanger's hashChanged
event to determine if your conditions are met (ie when old hash = view 3's pattern) you could fire a Router.navTo("view1sRouteName")
. 这不是非常优雅,但是您可以使用HashChanger的hashChanged
事件来确定您的条件是否得到满足(即,当旧的hash =视图3的模式时),您可以触发Router.navTo("view1sRouteName")
。 You could also instantiate a History sap.ui.core.routing
object to get for certain whether the direction is forward or backward using History.getDirection()
. 您还可以使用History.getDirection()
实例化History sap.ui.core.routing
对象,以确定方向是向前还是向后。
Make sure you read the APIs on the History and HashChanger's dependencies so that you are instantiating at the right time. 确保阅读了History和HashChanger的依赖项上的API,以便在正确的时间实例化。
I did not get it to work reliably with the most voted answer.我没有让它与投票最多的答案可靠地工作。
This might be against better advice in the documentation, but is working for me:这可能与文档中更好的建议相反,但对我有用:
...
"sap/ushell/ui5service/ShellUIService"
], function (BaseController, JSONModel, formatter, IconPool, ShellUIService) {
...
onInit: function () {
this.oShellUIService = new ShellUIService({
scopeObject: this.getOwnerComponent(),
scopeType: "component"
});
this.oShellUIService.setBackNavigation(this._navBack.bind(this));
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.