如何从 Odata Service SAP ui5 读取聚合实体

How to read an aggregated entity from Odata Service SAP ui5

在 OData 模型 V2 中,我正在努力读取模拟服务器的 odata:

我想访问与父实体关联的子实体。

Open_Station我可以导航to_Order_Header:

[{
    "results": [
        {
            "__metadata": {
                "id": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
                "uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')",
                "type": "cds_zui_check_dialog.Open_StationType"
            },

            "Station": "CHE1",
            "Task": "5246",
            "to_Order_Header": {
                "__deferred": {
                    "uri": "http://WebService/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"
                }
            }
        }
    ]
}

]

然后从 to_Order_Header,我可以导航到 Order_Item 或股票:

[{
"__metadata" : {
  "id" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
  "uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')",
  "type" : "cds_zui_check_dialog.Order_HeaderType"
},
"OrderNumber" : "00000000100000000853",
"Station" : "CHE1",
"OrderIndicator" : "",
"to_Order_Items" : {
  "__deferred" : {
    "uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Order_Items"
  }
},
"to_Stock" : {
  "__deferred" : {
    "uri" : "http://WebService/Order_Header(OrderNumber='00000000100000000853',Station='CHE1',OrderIndicator='')/to_Stock"
  }

} ]

在我的控制器中,我有一个方法 ReadOdata 读取这样的数据:

ReadOdata: function()
{
   var oModel = new sap.ui.model.odata.v2.ODataModel("http://WebService");
   return new Promise(function(resolve, reject)
   {
       oModel.read("Open_Station(Station='CHE1',Task='5246')/to_Order_Header", {
           
           success : function (data) {
              resolve(data);
           },
           error: function (oError) {
               reject(oError);
           }
       });
   });
   
},

我总是遇到这样的失败:

Request failed with status code 404: GET Open_Station(Station='CHE1',Task='5246')/to_Order_Header 
- [{"code":404,"message":"Resource not found","persistent":false,"targets":["/Open_Station(Station='CHE1',Task='5246')/to_Order_Header"],"type":"Error"}]
 sap.ui.model.odata.ODataMessageParser

我想我想读取关联实体的方式是错误的。请帮助我。

我找到了解决办法。路径注释失败:

而不是写作:

 oModel.read("**to_Open_Station**(Station='CHE1',Task='5246')/to_Order_Header", {

我在写:

oModel.read("*Open_Station*(Station='CHE1',Task='5246')/to_Order_Header", {

在元数据中,NavigationProperty 被称为 to_Open_Station。