如何在用户单击消息弹出按钮时导航到另一个 XML 页面



View1.Controller.js

onClickRUSSIA: function() {
            var dialog = new Dialog({
                title: 'Default Message',`enter code here`
                type: 'Message',
                content: new Text({
                    text: 'Country  :  RUSSIA n Contenent   :   ASIA n language:RUSSIAN.'
                }),
                beginButton: new Button({
                    text: 'OK',
                    press: function() {
                        dialog.close();
                    }
                }),
                endButton: new Button({
                    text: 'More Info',
                    press: function() {
                        //this.getRouter().navTo("mohan");
                        var router = sap.ui.core.UIComponent.getRouterFor();
                        router.navTo("View2");
                    }
                }),
                afterClose: function() {
                    dialog.destroy();
                }
            });
            dialog.open();
        },

组件.js

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/Device",
    "Test1/model/models"
], function(UIComponent, Device, models) {
    "use strict";
    return UIComponent.extend("Test1.Component", {
        metadata: {
            //rootView: "test1.webapp.view.App",
            manifest: "json",
            routing: {
                config: {
                    viewType: "XML",
                    viewPath: "test1.webapp.view",
                    controlId: "rootControl",
                    controlAggregation: "pages",
                    //routerClass: "Test1.controller",
                    transition: "slide"
                },
                routes: [
                    {
                        pattern: "",
                        name: "default",
                        view: "view1"
                    }, {
                        pattern: "mohan",
                        name: "view2",
                        View: "view2"
                    }
                ]
                // targets: {
                //  page1: {
                //      viewName: "View1",
                //      viewLevel: 0
                //  },
                //  page2: {
                //      viewName: "View2",
                //      viewLevel: 1
                //  }
                // }
            }
        },
        init: function() {
            // call the base component's init function
            UIComponent.prototype.init.apply(this, arguments);
            jQuery.sap.require("sap.m.routing.RouteMatchedHandler");
            jQuery.sap.require("sap.ui.core.routing.HashChanger");
            sap.ui.core.UIComponent.prototype.init.apply(this, arguments);
            this._router = this.getRouter();
            // set the device model
            this.setModel(models.createDeviceModel(), "device");
            //initlialize the router
            this._routeHandler = new sap.m.routing.RouteMatchedHandler(this._router);
            this._router.initialize();
        }
    });
});
  1. 您必须为您的控制器/视图获取路由器。由于this不是你的控制器里面endButton.press(),所以你必须使用一个辅助变量that
  2. 您必须Router.navTo()提供要导航到的路由的名称。所以它必须是 view2 而不是 View2。
var that = this;
var dialog = new Dialog({
  ...
  endButton: new Button({
    text: 'More Info',
    press: function() {
      var router = sap.ui.core.UIComponent.getRouterFor(that);
      router.navTo("view2");
    }
  }),
  ...
this.getOwnerComponent().getTargets().display("page1");

最新更新