SAPUI5 Walkthrough Step 33: Routing Back and History

Step 33: Routing Back and History    路由退回   修改webapp/view/Detail.view.xml文件, 设置Page的 showNavButton 属性为"true" , 并增加处理事件 navButtonPress="onNavButtonPress"。
<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);
            }
        }
    });
});

 

上一篇:33、为何需要把 TCP/IP 协议栈分成 5 层(或7层)?开放式回答。


下一篇:33、搜索旋转排序数组 | 算法(leetode,附思维导图 + 全部解法)300题