其他分享
首页 > 其他分享> > SAPUI5 Walkthrough Step 33: Routing Back and History

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);
            }
        }
    });
});

 

标签:function,oRouter,33,SAPUI5,Back,ui,var,sap,History
来源: https://www.cnblogs.com/keyuming/p/15124023.html