<mvc:View xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" controllerName="sap.ui.demo.walkthrough.controller.Detail"> <Page title="Walkthrough - Details" showNavButton="true" navButtonPress="onNavButtonPress"> <ObjectHeader intro="{invoice>ShipperName}" title="{invoice>ProductName}"></ObjectHeader> </Page> </mvc:View>
修改 webapp/controller/Detail.controller.js 文件, 增加 onNavButtonPress 事件的处理
sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/ui/core/routing/History" ], function(Controller, History) { "use strict"; return Controller.extend("sap.ui.demo.walkthrough.controller.Detail", { onInit: function() { var oRouter = this.getOwnerComponent().getRouter(); oRouter.getRoute("detail").attachPatternMatched(this._onObjectMatched, this); }, _onObjectMatched: function(oEvent) { this.getView().bindElement({ path: "/" + window.decodeURIComponent(oEvent.getParameter("arguments").invoicePath), model: "invoice" }); }, onNavButtonPress: function(oEvent) { var oHistory = History.getInstance(); var sPreviousHash = oHistory.getPreviousHash(); if (sPreviousHash !== undefined) { window.history.go(-1); } else { var oRouter = this.getOwnerComponent().getRouter(); oRouter.navTo("overview", {}, true); } } }); });