【问题标题】:SAPUI5 Expand the model in the manifestSAPUI5 展开清单中的模型
【发布时间】:2017-07-04 07:37:38
【问题描述】:

我想向 manifest.json 添加一个新模型。 该模型应该被扩展。

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"
    }

如何将展开添加到模型中?

【问题讨论】:

    标签: model sapui5


    【解决方案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 附加了相应的参数:

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

    JSON response

    【讨论】:

      猜你喜欢
      • 2017-10-04
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2017-03-19
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多