2017-10-10 31 views
0

負載的OData我已經配置的信息用於從SAP UI5訪問我OData服務中在manifest.json失敗時在SAPUI5

{ 
"sap.app": { ... 
    }, 
    "dataSources": { 
     "Test": { 
      "uri": "/sap/opu/odata/sap/ZHCM_SRV/", 
      "type": "OData", 
      "settings": { 
       "odataVersion": "2.0", 
       "localUri": "localService/metadata.xml" 
      } 
     } 
    } ... 
"sap.ui5": { 
    "rootView": { 
     "viewName": "test.view.App", 
     "type": "XML", 
     "id": "app" 
    }, ... 
    "models": { 
     "i18n": { 
      "type": "sap.ui.model.resource.ResourceModel", 
      "settings": { 
       "bundleName": "test.i18n.i18n" 
      } 
     }, 
     "Test": { 
      "type": "sap.ui.model.odata.v2.ODataModel", 
      "settings": { 
       "defaultOperationMode": "Server", 
       "defaultBindingMode": "TwoWay", 
       "defaultCountMode": "None" 
      }, 
      "dataSource": "Test" 
     } 
    }, 
    "routing": { ... 
} 

以我Component.js我有:

init: function() { 

     UIComponent.prototype.init.apply(this, arguments); 

     this.getRouter().initialize(); 

     this.setModel(models.createDeviceModel(), "device"); 

     // I get the Url from configuration in Manifest.json 
     var sServiceUrl = this.getMetadata().getManifestEntry("sap.app").dataSources["Test"].uri; 

     // I create the OData 
     var sabModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl); 

     // Load the MetaData. 
     sabModel.getServiceMetadata(); 

     // Binding to the Model. 
     this.setModel(sabModel, "Sabbatical"); 

時我正在檢查oModel我可以看到我已經實例化模型,但它是空的,沒有數據...你有這種行爲嗎?任何建議?

非常感謝! CBR

回答

0

到目前爲止您所做的工作是:建立與模型的連接。

如果您想要用數據填充它,可以通過將模型綁定到UI元素(例如,一個table,或通過編程讀取數據:sap.ui.model.Model getProperty()。

在你的情況,你會打電話

var yourVariable = sabModel.getProperty('path/to/your/property'); 
+0

謝謝米歇爾, 我發送一個結構(1陣列),我想不加載表或列表來管理它。 我會看看你告訴我的解決方案。 非常感謝! –

0

OData的機型不包含來自實體的任何數據開始。它只是模型實例化期間請求的元數據。

實體集可以聚集在以下幾種方式:

  • 手動經由CRUD的API
  • 讓UI5手柄請求自動根據聚集或元件綁定定義(優選的):

    對後端的請求由ODat提供的列表綁定,元素綁定和CRUD功能觸發一個模型。屬性綁定不會觸發請求。

看看文檔OData V2 Model
這裏是從similar answer一個例子:https://embed.plnkr.co/wAlrHB/


注意:無論getProperty也不getObject發送任何請求,但是從高速緩存返回的值的副本。

+0

非常感謝Boghyon, 我想管理1條我從後端接收的條目。我不想在表格或列表中顯示信息,但是需要在textedits或Inputfields等常規字段中顯示信息。我在幾個地方閱讀了如何填寫這些對象,但不知道如何管理自己從OData服務獲得的信息。 非常感謝,我想我會回到你們所有人的! –

+0

@ CBR_2017在這種情況下,您可以[利用元素綁定](https:// stackoverflow。com/a/44280286/5846045)(w /'$ select'),直接在輸入控件的'value'屬性上綁定輸入字段。從OData模型[ContextBinding](https://openui5.hana.ondemand.com/#/api/sap.ui.model.odata.v2.ODataContextBinding)管理條目w/API(通過'myInput.getBindingContext' )或[PropertyBinding](https://openui5.hana.ondemand.com/#/api/sap.ui.model.odata.ODataPropertyBinding)實例(通過'myInput.getBinding(「value」)')。 – boghyon

+0

對不起Boghyon, 我對這項技術很新鮮。我有2天的時間嘗試你所說的話,但我無法在OModel中看到我的信息。 我在Component.js中加載此信息,我想根據上下文中上傳的值導航到一個或另一個視圖。我沒有任何對象在我的屏幕上,因爲我想事先確定路線...... –