【问题标题】:How to use the odata expand-parameter in a SAPUI5 Table?如何在 SAPUI5 表中使用 odata 扩展参数?
【发布时间】:2019-11-07 04:46:55
【问题描述】:

我想显示来自 SAPUI5 表内具有一对多关系的 2 个 odata 实体的数据。

我尝试了多种在表格中引用的方式(例如条目/标题)。调试显示条目中的数据已接收但未显示在表格中。

<Table
    items="{
        path: '/Line',
        parameters : {
        expand : 'entries'
        }
    }" >
    <columns>
        <Column />
        <Column />
    </columns>
    <items>
        <ColumnListItem>
        <Label text="{ID}" />
        <Label text="{title} 
            {shape}" />
        </ColumnListItem>
    </items>
</Table>

这是我的 metadata.xml

<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:sap="http://www.sap.com/Protocols/SAPData" xmlns:ux="http://www.sap.com/Protocols/OData4SAP/UX" xmlns:gp="http://www.sap.com/Protocols/SAPData/GenericPlayer" Version="1.0">
    <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="2.0">
        <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="TimelineService">
            <EntityType Name="Entry">
                <Key>
                    <PropertyRef Name="ID"/>
                </Key>
                <Property Name="ID" Type="Edm.Int32" Nullable="false"/>
                <Property Name="title" Type="Edm.String"/>
                <Property Name="startDate" Type="Edm.DateTimeOffset"/>
                <Property Name="shape" Type="Edm.String"/>
                <Property Name="lineID_ID" Type="Edm.Int32"/>
                <NavigationProperty Name="lineID" Relationship="TimelineService.Entry_lineID" FromRole="Entry" ToRole="Line"/>
            </EntityType>
            <EntityType Name="Line">
                <Key>
                    <PropertyRef Name="ID"/>
                </Key>
                <Property Name="ID" Type="Edm.Int32" Nullable="false"/>
                <NavigationProperty Name="entries" Relationship="TimelineService.Entry_lineID" FromRole="Line" ToRole="Entry"/>
            </EntityType>
            <Association Name="Entry_lineID">
                <End Type="TimelineService.Entry" Multiplicity="*" Role="Entry"/>
                <End Type="TimelineService.Line" Multiplicity="0..1" Role="Line"/>
                <ReferentialConstraint>
                    <Principal Role="Line">
                        <PropertyRef Name="ID"/>
                    </Principal>
                    <Dependent Role="Entry">
                        <PropertyRef Name="lineID_ID"/>
                    </Dependent>
                </ReferentialConstraint>
            </Association>
            <EntityContainer Name="EntityContainer" m:IsDefaultEntityContainer="true">
                <EntitySet Name="Entry" EntityType="TimelineService.Entry"/>
                <EntitySet Name="Line" EntityType="TimelineService.Line"/>
                <AssociationSet Name="Entry_lineID" Association="TimelineService.Entry_lineID">
                    <End EntitySet="Entry" Role="Entry"/>
                    <End EntitySet="Line" Role="Line"/>
                </AssociationSet>
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

【问题讨论】:

    标签: javascript odata sapui5 expand mockserver


    【解决方案1】:

    试试下面的解决方案:

    打开您的控制器,并执行绑定元素到您的上下文控制器。

    this.getView().bindElement({
        path : "/Line",
        parameters : {
            "expand" : "entries"
        }
    });
    

    现在,修改您的视图

    <Table items="{
        path: 'entries'
    }">
    <columns>
        <Column />
        <Column />
    </columns>
    <items>
        <ColumnListItem>
        <Label text="{ID}" />
        <Label text="{title} 
            {shape}" />
        </ColumnListItem>
    </items>
    

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      相关资源
      最近更新 更多