如何从controller.xml中的sapui5应用程序URL获取值

时间:2016-12-02 04:26:42

标签: sapui5

我有业务需求,我正在使用基于云的SAP Web工具开发部署在HCP中的sapui5员工休假应用程序。

两种类型的员工将使用两个不同的网址访问此应用程序,其参数为“IT”或“BPO”:

https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/IT

https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/BPO

后端:我开发了一个REST服务,当我使用以下网址为IT或BPO特定员工执行GET请求时,以jSON格式向我提供员工详细信息:

/irc.com/ircit/empleave/rest/empleave/item/requestor/IT

/irc.com/ircit/empleave/rest/empleave/item/requestor/BPO

查看: 我使用了一个xml视图MyRequestList,它将以表格格式显示来自IT和BPO的所有请求。

要求:

我需要根据url中传递的参数来获取数据。例如,当用户点击下面的url时,MyRequestView的标题应该是IT Employee,并且只有IT员工的请求应该出现并且对于BPO是相同的

https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/IT

问题:

如何从应用程序URL获取参数“IT”或“BPO”并从控制器传递给视图。

Jquery.sap.GetURIParameter.Get(“MyParam”)没有获取url参数'IT'或'BPO'。我应该使用哪种方法。

RouterConfig:

{
    "_version": "1.1.0",
    "sap.app": {
        "_version": "1.1.0",
        "id": "ircit.irc",
        "type": "application",
        "i18n": "/webapp/i18n/i18n.properties",
        "title": "{{appTitle}}",
        "description": "{{appDescription}}",
        "applicationVersion": {
            "version": "1.0.0"
        }
    },
    "sap.ui": {
        "_version": "1.1.0",
        "technology": "UI5",
        "deviceTypes": {
            "desktop": true,
            "tablet": false,
            "phone": false
        },
        "supportedThemes": [
            "sap_bluecrystal"
        ]
    },
    "sap.ui5": {
        "_version": "1.1.0",
        "rootView": "ircit.irc.view.App",
        "dependencies": {
            "minUI5Version": "1.30",
            "libs": {
                "sap.m": {}
            }
        },
        "contentDensities": {
            "compact": true,
            "cozy": true
        },
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "settings": {
                    "bundleName": "ircit.irc.i18n.i18n"
                }
            }
        },
        "resources": {
            "css": [
                {
                    "uri": "/webapp/css/style.css"
                }
            ]
        },
        "routing": {
            "config": {
                "routerClass": "ircit.generic.utils.CustomRouter",
                "viewType": "XML",
                "viewPath": "ircit.irc.view",
                "controlId": "app",
                "fullWidth": true,
                "controlAggregation": "pages",
                "bypassed": {
                    "target": [
                        "notFound"
                    ]
                }
            },
            "routes": [
                /*{
                    "pattern": "",
                    "name": "myRequests",
                    "target": "myRequests"
                },*/
{
                    "pattern": "/{id}",
                    "name": "myRequests",
                    "target": "myRequests"
                },

                {
                    "pattern": "/create",
                    "name": "create",
                    "target": "create"
                },
                {
                    "pattern": "/create/{id}",
                    "name": "copy",
                    "target": "create"
                },
                {
                    "pattern": "/id={id}",
                    "name": "Display",
                    "target": "display"
                }
            ],
            "targets": {
                "myRequests": {
                    "viewName": "MyRequests",
                    "viewId": "myRequests",
                    "viewLevel": 1
                },
                "display": {
                    "viewName": "Display",
                    "viewId": "display",
                    "viewLevel": 2
                },
                "create": {
                    "viewName": "Create",
                    "viewId": "create",
                    "viewLevel": 2
                },
                "copy": {
                    "viewName": "Create",
                    "viewId": "create",
                    "viewLevel": 2
                },
                "notFound": {
                    "viewName": "NotFound",
                    "viewId": "notFound"
                }
            }
        }
    },
    "sap.platform.hcp": {
        "uri": "webapp",
        "_version": "1.1.0"
    }
}

MyRequestController:

onInit: function() {
            // set create option (cteate and copy button)
            var bValue = jQuery.sap.getUriParameters().get("showCreate");
            var oBtn = this.byId("btnCreate");
            oBtn.setVisible(bValue !== "false");
            var oColumn = this.byId("colCopy");
            oColumn.setVisible(bValue !== "false");

            this.getRouter().attachRouteMatched(jQuery.proxy(this.onRouteMatched, this));
        },

1 个答案:

答案 0 :(得分:0)

我会宣布另外两条路线:1。IT和2. BPO。显然,您希望导航到“myRequests”,因此将跳过为它们创建任何新目标。所以,有两条路线:

{
                    "pattern": "IT",
                    "name": "IT",
                    "target": "myRequests"
                },
                {
                    "pattern": "BPO",
                    "name": "BPO",
                    "target": "myRequests"
                },

接下来我们如何知道哪条路线被击中并相应地处理它。所以,我们所做的是,获取路由并将处理程序与它相关联:

 onInit: function() {
        var oComponent = this.getOwnerComponent();
        this._router = oComponent.getRouter();
        this._router.getRoute("IT").attachPatternMatched(this._routePatternMatchedForIT, this);
        this._router.getRoute("BPO").attachPatternMatched(this._routePatternMatchedForBPO, this);

    },
    _routePatternMatchedForIT: function (oEvent) {
        console.log('Shout for IT');
        var sRouteName = oEvent.getParameter('name');
        // Call the service : /irc.com/ircit/empleave/rest/empleave/item/requestor/IT
    },
    _routePatternMatchedForBPO: function (oEvent) {
        console.log('Shout for BPO');
        // Call the service : /irc.com/ircit/empleave/rest/empleave/item/requestor/BPO
        var sRouteName = oEvent.getParameter('name');
    }

请注意,两个不同的路径有两种不同的处理程序。将调用哪个处理程序将完全基于URL的形成方式(使用IT或BPO)。

如果有帮助,请告诉我。