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

时间:2016-04-27 06:53:15

标签: sapui5 web-ide

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

        },

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

2 个答案:

答案 0 :(得分:0)

  1. 您必须获取控制器/视图的路由器。由于this不是endButton.press()内的控制器,因此您必须使用辅助变量that
  2. 您必须提供Router.navTo()要导航到的路线的名称。所以它必须是 v iew2而不是 V iew2。
  3. 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");
        }
      }),
      ...
    

答案 1 :(得分:-1)

this.getOwnerComponent().getTargets().display("page1");