如何从controller.xml中的sapui5应用程序URL获取值
我有一个业务需求,我正在使用基于云的sap webide工具开发部署在HCP中的sapui5员工休假应用程序 两种类型的员工将使用两个不同的url访问此应用程序,参数为“IT”或“BPO”:如何从controller.xml中的sapui5应用程序URL获取值,sapui5,Sapui5,我有一个业务需求,我正在使用基于云的sap webide工具开发部署在HCP中的sapui5员工休假应用程序 两种类型的员工将使用两个不同的url访问此应用程序,参数为“IT”或“BPO”: https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/IT https://webidetesting453789-inf98834.dispatcher.int.sap.h
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服务,当我使用以下url为IT或特定于BPO的员工发出GET请求时,它会以jSON格式为我提供员工详细信息,如:
/irc.com/ircit/empleave/rest/empleave/item/requestor/IT
或
视图:
我使用了一个xml视图MyRequestList,它将以表格格式显示来自IT和BPO的所有请求
要求:
我需要根据url中传递的参数获取数据。例如,当用户单击下面的url时,MyRequestView的标题应该是IT员工,并且只显示对IT员工的请求,对于BPO也是如此
问题:
如何从应用程序url获取参数“IT”或“BPO”,并从控制器传递到视图
Jquery.sap.GetURIParameter.GetMyParam没有获取url参数“IT”或“BPO”。我应该使用什么方法
路由配置:
{
"_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。它和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是如何使用它或BPO形成的
如果有帮助,请告诉我。您可以粘贴路由器配置吗?另外,如果您使用的是基于哈希的路由,您可能需要研究以下方法:attachPatternMatched感谢Rahul,我将实现此方法并让您知道结果。嗨Rahul,除了路由,我还需要单击url中的参数it/bpo来相应地设置我的MyRequestView标题。知道如何获取相同的名称吗?谢谢Rahul,我会实现这一点,并让你知道。拉胡尔成功了…满分,非常感谢你的帮助。最后一个问题。我需要这个var sRouteName值,即它或bpo来设置我的MyRequestView标题。我如何做。我是否必须创建另一个模型并将其设置为查看您的建议?最后一个问题。我需要这个var sRouteName值,即它或bpo来设置我的MyRequestView标题。我该如何做。我是否必须创建另一个模型并将其设置为查看您的建议?
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');
}