Launcpad标头后退按钮的事件处理程序

Mil*_*son 1 javascript jquery sapui5

在某些情况下,我需要覆盖Launchpad标头后退按钮的事件。我尝试了很多类似的事情:

try {
	sap.ui.getCore().byId("backBtn").attachPress(this, function(oEvent)  {
		oEvent.preventDefault();
 }.bind(this));
} catch (err) {
	console.log(err);
}
Run Code Online (Sandbox Code Playgroud)

要么

$('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));
Run Code Online (Sandbox Code Playgroud)

在这些代码中,我只是试图阻止导航,然后返回。没用 在某些情况下,我想导航到某些视图。例如:

如果用户在视图3中->单击启动板后退按钮->导航到视图1(不是先前的导航目标)

但是我无法停止导航机制以返回到先前的目标。

我将不胜感激任何帮助或想法。

Kyl*_*yle 5

首先,您需要在manifest.json中注册ShellUIService。

在sap.ui5下的manifest.json中:

...
"sap.ui5": {
     ...
     "services": {
        "ShellUIService": {
            "factoryName": "sap.ushell.ui5service.ShellUIService"
        }
    }
    ...
}
...
Run Code Online (Sandbox Code Playgroud)

那么您可以在控制器中(或从组件中)覆盖默认行为

this.getOwnerComponent().getService("ShellUIService").then(function(oShellService) {
    oShellService.setBackNavigation(function() {
        //either do nothing to disable it, or add your own back nav logic
    })
Run Code Online (Sandbox Code Playgroud)

})