0

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

2 回答 2

1
  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");
    }
  }),
  ...
于 2016-04-27T11:10:45.547 回答
0
this.getOwnerComponent().getTargets().display("page1");
于 2016-12-25T14:36:20.630 回答