2017-07-04 59 views
1

我想向manifest.json添加新模型。 該模型應該被擴展。SAPUI5展開清單中的模型

https://myPath/services/myService.xsodata/SubPath?$expand=CustomerRef 

,因此DataSource定義:

"dataSources": { 
    "mainService": { 
     "uri": "/myPath/services/myService.xsodata/", 
     "type": "OData", 
     "settings": { 
      "odataVersion": "2.0", 
      "localUri": "localService/myService.xsodata/metadata.xml" 
     } 
    } 

和模型的定義:

"models": { 
    "Customer": { 
     "type": "sap.ui.model.odata.v2.ODataModel", 
     "settings": { 
      "useBatch": "false" 
     }, 
     "dataSource": "mainService" 
    } 

我如何添加擴展到模型?

回答

1

數據無法在模型定義本身中展開。所述expand parameter要被用於其中的視圖和數據之間的結合被定義爲mentioned in the documentation

某些參數必須不被包括在每一個請求,但應該只被添加到特定聚合或元件綁定如$ expand或$ select。爲此,綁定方法提供了傳遞參數映射的選項,然後參數映射將包含在針對此特定綁定的所有請求中。

例如, (從https://embed.plnkr.co/wAlrHB/):

<List items="{ 
    path: 'odataModel>/Products', 
    parameters: { 
    expand: 'Category, Supplier', 
    select: 'ProductName, UnitsInStock, Category/CategoryName, Supplier/Country' 
    }, 
    sorter: [ 
    { 
     path: 'Category/CategoryName', 
     group: true 
    } 
    ], 
    filters: [ 
    { 
     path: 'Supplier/Country', 
     operator: 'EQ', 
     value1: 'UK' 
    } 
    ] 
}"> 
    <ObjectListItem title="{odataModel>ProductName}" number="{odataModel>UnitsInStock}"/> 
</List> 

結合(而不是型號)然後將send a request ...

請求,後端由列表綁定(ODataListBinding)

觸發

...帶有由UI5附加的各個參數:

"http://services.odata.org/V2/Northwind/Northwind.svc/Products?$skip=0&$top=100&$orderby=Category/CategoryName%20asc&$filter=Supplier/Country%20eq%20%27UK%27&$expand=Category%2c%20Supplier&$select=ProductName%2c%20UnitsInStock%2c%20Category%2fCategoryName%2c%20Supplier%2fCountry" 

==>result

+0

什麼將是方法如果我想從外部傳遞屬性以便將記錄更改爲升序和降序?我怎樣才能做到這一點 ? – 2017-08-23 15:39:15

+0

@johndeer看看節[「手動排序和過濾的聚集綁定」(https://sapui5.hana.ondemand.com/#docs/guide/ec79a5d5918f4f7f9cbc2150e66778cc.html#loioec79a5d5918f4f7f9cbc2150e66778cc__section_N100CF_N10013_N10001) – boghyon

+0

謝謝你。我明白了。現在是另一個問題,如果我想取平均值。因爲odata 2.0不具備此功能。 – 2017-08-28 09:00:31