我有业务需求,我正在使用基于云的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服务,当我使用以下URL为IT或BPO特定员工执行GET请求时,以jSON格式向我提供员工详细信息,例如: /irc.com/ircit/empleave/rest/empleave/item/requestor/IT 要么 /irc.com/ircit/empleave/rest/empleave/item/requestor/BPO 查看:我使用了一个xml视图MyRequest,它将以表格格式显示来自IT或BPO的请求。
带有下拉列表的创建视图(XML视图)从“valueHelp”模型填充,页面标题等根据“IT”或“BPO”参数进行更改。
我在“MyRequest”视图的页脚中有一个创建按钮,它将调用“创建”视图。
要求:
当我访问链接时 https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/IT
我收到了IT员工的所有请求,并且在MyRequest视图中收到了BPO的相同请求
但我的要求是在相同的MyRequest视图中,当我点击创建按钮时,它应该获取url参数,即IT或BPO,并导航到带有该url参数的Create视图,以便我可以设置valuehelp模型并更改相应的页面标题和ui组件的名称。
RouterConfiguration。
"routes": [{
"pattern": "",
"name": "myRequests",
"target": "myRequests"
}, {
"pattern": "IT",
"name": "IT",
"target": "myRequests"
}, {
"pattern": "BPO",
"name": "BPO",
"target": "myRequests"
}, {
"pattern": "create",
"name": "Create",
"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"
}
}
}
},
MyRequest控制器
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');
}
onCreatePress: function(oEvent) {
//var sRouteName = this.getViewName();
//alert(sRouteName);
/*var sRouteName = oEvent.getParameter("name");
if (sRouteName === "IT") {
this.getRouter().navTo("create/IT");
}
if (sRouteName === "BPO"){
this.getRouter().navTo("create/BPO");
}*/
this.getRouter().navTo("Create");
},
MyRequest查看创建按钮
Button id="btnCreate" text="{i18n>btnOpenCreateView}" press="onCreatePress" type="Accept" visible="true"/>
创建控制器
onRouteMatched: function(oEvent) {
var sRouteName = oEvent.getParameter("name");
//alert(sRouteName);
if (sRouteName === "create") {
this.routeName = sRouteName;
this._loadDataDC();
}
请建议我如何修改创建控制器和MyRequest控制器,以便从网址获取值IT或BPO
https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/IT
or
https://webidetesting453789-inf98834.dispatcher.int.sap.hana.ondemand.com/webapp/index.html#/BPO
并在按下创建按钮时使用事件onCreatePress()传递它,以便我可以导航到Create视图并加载相应的valueHelp模型以及设置页面标题和其他ui组件。
答案 0 :(得分:1)
使用以下代码获取哈希:
使用HashChanger:
var oHashChanger = new sap.ui.core.routing.HashChanger();
var sHash = oHashChanger.getHash(); // it will return IT or BPO
使用窗口对象:
var sHash = window.location.hash; // it will return #/IT or #/BPO.
实际上寻找更好的答案。