2016-12-02 58 views
-2

我有一个业务需求,我正在开发使用基于云的sap webide工具在HCP中部署的sapui5员工离职应用程序。我如何从controller.xml中的sapui5应用程序URL获取值

两种类型的员工将访问使用两个不同的URL与参数的这种应用是“IT”或“外包”:

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视图MyRequestList,它将以表格形式向我显示来自IT和BPO的所有请求。

要求:

我需要根据在url.For例子传递的参数来获取数据时,在下面的网址,用户点击后,MyRequestView的标题应该是IT员工和IT只请求员工应该出现并且与BPO相同。

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

问:

如何从应用程序URL参数“IT”或“外包”,并传递给从控制器的看法。 (“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)); 
     }, 
+0

你能否粘贴你的路由器配置?另外,如果你使用基于散列的路由,你可能想看看方法:attachPatternMatched(https://help.sap.com/saphelp_uiaddon20/helpdata/en/23/66345a94f64ec1a80f9d9ce50a59ef/content.htm) –

回答

0

我将宣布两个途径:1,IT和BPO 2。显然,你想导航到'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)。

让我知道这是否有帮助。

+0

谢谢拉胡尔,我会实现这一点,并会让你知道结果。 – Smith

+0

嗨拉胡尔,除了路由,我会需要参数it/bpo从点击的URL来设置MyRequestView标题相应。任何想法如何获取相同? – Smith

+0

非常感谢Rahul,我会执行这个并让你知道。 – Smith

相关问题