Xml UI5 OData将多个实体绑定到sap.m.Table

Xml UI5 OData将多个实体绑定到sap.m.Table,xml,odata,sapui5,Xml,Odata,Sapui5,我正在使用Northwind数据库测试UI5应用程序。我正试图将两个实体(产品和供应商)整合在一起。我想在表格中显示每个产品的供应商 我在sap.m.Table的items参数中使用了参数:{expand:'Supplier'},使其正常工作,但是,这会返回每个字段的所有数据 因此,它返回了类似于以下内容的内容(前两列来自/Products,最后一列来自/Supplier: ProductName UnitPrice SupplierName Bread 10

我正在使用Northwind数据库测试UI5应用程序。我正试图将两个实体(产品和供应商)整合在一起。我想在表格中显示每个产品的供应商

我在
sap.m.Table
items
参数中使用了
参数:{expand:'Supplier'}
,使其正常工作,但是,这会返回每个字段的所有数据

因此,它返回了类似于以下内容的内容(前两列来自
/Products
,最后一列来自
/Supplier

ProductName    UnitPrice    SupplierName
Bread          10           Big Bread Co
目前,我的路径设置为:

items="{
    path: '/Products',
    sorter: {
        path: 'ProductName',
        descending: false
    }
}"
我尝试通过以下方式访问供应商公司名称:

然而,我明白为什么这不起作用,但我不知道如何让它起作用

谢谢你的帮助

请看下面我尝试的内容:

<Table 
    id="table" 
    width="auto" 
    class="sapUiResponsiveMargin" 
    items="{
        path: '/Products',
        sorter: {
            path: 'ProductName',
            descending: false
        }
    }" 
    noDataText="{worklistView>/tableNoDataText}"
    busyIndicatorDelay="{worklistView>/tableBusyDelay}"
    growing="true"
    growingScrollToLoad="true"
    updateFinished="onUpdateFinished">

    <!--    parameters:{expand : 'Category'}, -->
    <headerToolbar>
        <Toolbar id="toolbar">
            <Title id="tableHeader" text="{worklistView>/worklistTableTitle}" />
            <ToolbarSpacer />
            <SearchField id="searchField" tooltip="{i18n>worklistSearchTooltip}" search="onSearch" width="auto" />
        </Toolbar>
    </headerToolbar>
    <columns>
        <Column id="nameColumn">
            <Text text="{i18n>tableNameColumnTitle}" id="nameColumnTitle" />
        </Column>
        <Column id="unitNumberColumn" hAlign="End">
            <Text text="{i18n>tableUnitNumberColumnTitle}" id="unitNumberColumnTitle" />
        </Column>
        <Column>
            <Text text="SupplierName" id="SupplierName" />
        </Column>
    </columns>
    <items>
        <ColumnListItem type="Navigation" press="onPress">
            <cells>
                <ObjectIdentifier title="{ProductName}" />
                <ObjectNumber number="{ path: 'UnitPrice', formatter: '.formatter.numberUnit' }" />
                <Text text="{Suppliers/CompanyName}" />
            </cells>
        </ColumnListItem>
    </items>
</Table>

产品:

<EntityType Name="Product">
    <Key>
        <PropertyRef Name="ProductID" />
    </Key>
    <Property xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="ProductID" Type="Edm.Int32" Nullable="false" p6:StoreGeneratedPattern="Identity" />
    <Property Name="ProductName" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
    <Property Name="SupplierID" Type="Edm.Int32" />
    <Property Name="CategoryID" Type="Edm.Int32" />
    <Property Name="QuantityPerUnit" Type="Edm.String" MaxLength="20" FixedLength="false" Unicode="true" />
    <Property Name="UnitPrice" Type="Edm.Decimal" Precision="19" Scale="4" />
    <Property Name="UnitsInStock" Type="Edm.Int16" />
    <Property Name="UnitsOnOrder" Type="Edm.Int16" />
    <Property Name="ReorderLevel" Type="Edm.Int16" />
    <Property Name="Discontinued" Type="Edm.Boolean" Nullable="false" />
    <NavigationProperty Name="Category" Relationship="NorthwindModel.FK_Products_Categories" ToRole="Categories" FromRole="Products" />
    <NavigationProperty Name="Order_Details" Relationship="NorthwindModel.FK_Order_Details_Products" ToRole="Order_Details" FromRole="Products" />
    <NavigationProperty Name="Supplier" Relationship="NorthwindModel.FK_Products_Suppliers" ToRole="Suppliers" FromRole="Products" />
</EntityType>

供应商:

<EntityType Name="Supplier">
    <Key>
        <PropertyRef Name="SupplierID" />
    </Key>
    <Property xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation" Name="SupplierID" Type="Edm.Int32" Nullable="false" p6:StoreGeneratedPattern="Identity" />
    <Property Name="CompanyName" Type="Edm.String" Nullable="false" MaxLength="40" FixedLength="false" Unicode="true" />
    <Property Name="ContactName" Type="Edm.String" MaxLength="30" FixedLength="false" Unicode="true" />
    <Property Name="ContactTitle" Type="Edm.String" MaxLength="30" FixedLength="false" Unicode="true" />
    <Property Name="Address" Type="Edm.String" MaxLength="60" FixedLength="false" Unicode="true" />
    <Property Name="City" Type="Edm.String" MaxLength="15" FixedLength="false" Unicode="true" />
    <Property Name="Region" Type="Edm.String" MaxLength="15" FixedLength="false" Unicode="true" />
    <Property Name="PostalCode" Type="Edm.String" MaxLength="10" FixedLength="false" Unicode="true" />
    <Property Name="Country" Type="Edm.String" MaxLength="15" FixedLength="false" Unicode="true" />
    <Property Name="Phone" Type="Edm.String" MaxLength="24" FixedLength="false" Unicode="true" />
    <Property Name="Fax" Type="Edm.String" MaxLength="24" FixedLength="false" Unicode="true" />
    <Property Name="HomePage" Type="Edm.String" MaxLength="Max" FixedLength="false" Unicode="true" />
    <NavigationProperty Name="Products" Relationship="NorthwindModel.FK_Products_Suppliers" ToRole="Products" FromRole="Suppliers" />
</EntityType>

首先,扩展完整的
供应商
实体没有错。它不应该对响应的大小/加载时间产生巨大的影响

事实上,如果您打开Chrome开发工具并跟踪当前请求和下面我的解决方案的时间,这两个时间将非常相似(如果没有选择,速度会更快)

当您比较响应的大小时,它肯定会有所不同

  • 如果没有$select,您将获得
    内容长度:2547
  • 使用$select,您将获得
    内容长度:836
    (因此只有三分之一)
请注意,单位为字节!因此这两个请求仍然非常小


但要回答您的问题:理论上,
$select
操作符与嵌套URL结合使用应该会对您有所帮助

但是,请记住,在ODataV4中添加的嵌套URL

这是为您提供所需结果的URL

您可以看到我在主实体(产品)上应用了一个
$select
。如果您想要
产品的所有属性,但只需要
供应商的
公司名称
,只需将父级
$select
更改为
$select=*


您需要做两件事:

1.设置参数:

 items="{
   path: '/Products',
   parameters:{expand : 'Supplier'}
   sorter: {
            path: 'ProductName',
            descending: false
           }
 }"
2.绑定导航属性以获取属性

<Text text="{Supplier/CompanyName}"/>

请注意,您的供应商是错误的,因为
Supplier
是错误的 导航属性


PS:这是来自

的非常详细和有用的见解,感谢您的回复。我如何将嵌套URL包括到我的XML代码中(即,我的表行中)。这是一个URL参数,因此我尝试使用
聚合的
参数。