2016-12-05 73 views
0

如何配置manifest.json文件,以便當我運行mockserver(mockserver.html)然後它轉到本地json數據,並且當我運行index.html(主入口到應用程序)時,到遠程服務。我從文檔中獲取了一個樣本manifest.json文件,但不太清楚遠程和本地服務如何發揮作用。遠程和本地OData服務

{ 
"_version": "1.1.0", 
"sap.app": { 
    "_version": "1.1.0", 
    "id": "xxx", 
    "type": "application", 
    "title": "{{appTitle}}", 
    "description": "{{appDescription}}", 
    "applicationVersion": { 
     "version": "1.0.0" 
    }, 
    "dataSources": { 
       "mainService": { 
        "uri": "https://services.odata.org/V2/Northwind/Northwind.svc/", 
        "type": "OData", 
        "settings": { 
         "odataVersion": "2.0", 
         "localUri": "localService/metadata.xml" 
        } 
       } 
      } 
}, 

"sap.ui": { 
    "_version": "1.1.0", 
    "technology": "UI5", 
    "icons": { 
     "icon": "", 
     "favIcon": "", 
     "phone": "", 
     "[email protected]": "", 
     "tablet": "", 
     "[email protected]": "" 
    }, 
    "deviceTypes": { 
     "desktop": true, 
     "tablet": true, 
     "phone": true 
    }, 
    "supportedThemes": [ 
     "sap_hcb", 
     "sap_bluecrystal" 
    ] 
}, 

"sap.ui5": { 
    "_version": "1.1.0", 
    "rootView": { 
     "viewName": "xxx.view.Main", 
     "type": "XML" 
    }, 
    "dependencies": { 
     "minUI5Version": "1.30.0", 
     "libs": { 
      "sap.ui.core": {}, 
      "sap.m": {}, 
      "sap.ui.layout": {} 
     } 
    }, 
    "contentDensities": { 
     "compact": true, 
     "cozy": true 
    }, 
    "config": { 
      "productLocal": "localService/mockdata/products.json", 
      "productRemote": "/some remote end point" 
     }, 

    "products": { 
      "dataSource": "mainService" 
     } 
} 

}

控制器代碼

var oModel = new sap.ui.model.odata.ODataModel("/", true); 

       //var data = oModel; 
       //console.log(data); 
       var inputModel = new JSONModel("../model/inputs.json"); 
       var productsModel = new JSONModel(); 

       oModel.read("/ProductSet", 
        null, 
        null, 
        false, 
        function _OnSuccess(oData, response) { 
         console.log(oData); 
         console.log(response); 
         var data = {"ProductCollection" : oData.results}; 
         productsModel.setData(data); 


        }, 
        function _OnError(error) { 
         console.log(error); 
        }); 

       //set model(s) to current xml view 
       this.getView().setModel(inputModel, "inputModel"); 
       this.getView().setModel(productsModel); 

感謝您的幫助。

回答

0

您不需要觸摸manifest.json文件來模擬該服務。 事實上,在manifest.json dataSources-localUri的屬性:將相對URL作爲本地元數據文檔或註釋uri。不是爲了服務。

我希望你mockserver.html看起來是這樣的:

<!DOCTYPE HTML> 
<html> 
    <head> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta charset="utf-8"> 
     <title>MockServerTutorial</title> 
     <script id="sap-ui-bootstrap" 
      src="../../resources/sap-ui-core.js" 
      data-sap-ui-libs="sap.m" 
      data-sap-ui-theme="sap_bluecrystal" 
      data-sap-ui-xx-bindingSyntax="complex" 
      data-sap-ui-resourceroots='{"sap.ui.demo.MockServer": "../"}'> 
     </script> 
     <link rel="stylesheet" type="text/css" href="../css/style.css"> 
     <script> 
      sap.ui.getCore().attachInit(function() { 
       sap.ui.require([ 
        "sap/ui/demo/MockServer/localService/mockserver", 
        "sap/m/Shell", 
        "sap/ui/core/ComponentContainer" 
       ], function (mockserver, Shell, ComponentContainer) { 
        mockserver.init(); 
        new Shell({ 
         app: new sap.ui.core.ComponentContainer({ 
          height : "100%", 
          name : "MockServerTutorial" 
         }) 
        }).placeAt("content"); 
       }); 
      }); 
     </script> 
    </head> 
    <body class="sapUiBody" id="content"> 
    </body> 
</html> 

你可以定義你的模擬服務器如下:

sap.ui.define([ 
    "sap/ui/core/util/MockServer" 
], function(MockServer) { 
    "use strict"; 
    return { 
     /** 
     * Initializes the mock server. 
     * You can configure the delay with the URL parameter "serverDelay". 
     * The local mock data in this folder is returned instead of the real data for testing. 
     * @public 
     */ 
     init: function() { 
      // create 
      var oMockServer = new MockServer({ 
       rootUri: "/" 
      }); 
      // simulate against the metadata and mock data 
      oMockServer.simulate("../localService/metadata.xml", { 
       sMockdataBaseUrl: "../localService/mockdata", 
       bGenerateMissingMockData: true 
      }); 
      // start 
      oMockServer.start(); 
      jQuery.sap.log.info("Running the app with mock data"); 
     } 
    }; 
}); 

請確保您將定製處理的網址(過濾器/排序)和 函數正確導入mockserver.js

Read complete steps here

+0

蘇尼爾,我有我的應用程序兩個入口。一個用於模擬服務器另一個應用程序。我能夠使用Odata模型運行模擬服務器,但是當我嘗試加載index.html時,我得到有關加載路徑的錯誤。我更新我的問題與控制器模擬服務器工作,但未能加載索引,HTML – user557657

+0

'var oModel = new sap.ui.model.odata.ODataModel(「/」,true); var productsModel = new JSONModel(); oModel.read( 「/ ProductSet」, 空, 空, 假, 功能_OnSuccess(ODATA,響應){ VAR數據= { 「ProductCollection」:oData.results}; productsModel.setData(數據); (錯誤){ }, this.getView()。setModel(productsModel);' – user557657

+0

Sunil,在manifest.json中,上面的dataSources屬性uri有一些遠程https端點如果我想在本例中指向本地像「/」,那麼我需要更改清單文件每次? – user557657

相關問題