2016-12-02 61 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

相關問題