UI5 Object Attributes with Multiple Associations

时间:2018-01-23 19:16:28

标签: odata sapui5 sap

I have successfully created a list of objects to be displayed in UI5 and connected that list to an OData service:

<content>
    <List id="__list" items="{SalesList}">
        <items>
            <ObjectListItem title="{SalesTitle}">
                <attributes>
                    <ObjectAttribute title="Id" text="{Id}"/>
                    <ObjectAttribute title="Sales Code" text="{Cd}"/>
                </attributes>
            </ObjectListItem>
        </items>
    </List>
</content>

However, I want to add another attribute to the ObjectListItem called "Discription" that is pulled from a different data source (not SalesList). In the $metadata, I have an association that links the Sales Id to the Sales Description named SalesDiscription.

I attempted to find ways to display the Sales Discription within the ObjectListItem, but haven't had any success:

<content>
    <List id="__list" items="{SalesList}">
        <items>
            <ObjectListItem title="{SalesTitle}">
                <attributes>
                    <ObjectAttribute title="Id" text="{Id}"/>
                    <ObjectAttribute title="Sales Code" text="{Cd}"/>
                    <ObjectAttribute title="Discription" text="{Desc}" attributes="{SalesDescription}"/>
                </attributes>
            </ObjectListItem>
        </items>
    </List>
</content>

Removing the Id and Sales Code attribute, and moving the association call to the ObjectListItem does correctly display a list of SalesTitles and Descriptions, but I need the Id and Sales Code to be included in the attributes as well:

<content>
    <List id="__list" items="{SalesList}">
        <items>
            <ObjectListItem title="{SalesTitle}" attributes="{SalesDescription}">
                <attributes>
                    <ObjectAttribute title="Discription" text="{Desc}"/>
                </attributes>
            </ObjectListItem>
        </items>
    </List>
</content>

Does anyone know a way of including ObjectAttributes from two different $metadata associations? Or a least a way to display data in an ObjectListItem from two different sources (doesn't have to be attributes)?

1 个答案:

答案 0 :(得分:0)

你能试试吗?我正在使用'binding'属性设置绑定上下文。我假设SalesList与SalesDescription的关系是1:1。 (协会)。 “SalesDescription”也是导航属性的名称。

<content>
    <List id="__list" items="{SalesList}">
        <items>
            <ObjectListItem title="{SalesTitle}">
                <attributes>
                    <ObjectAttribute title="Id" text="{Id}"/>
                    <ObjectAttribute title="Sales Code" text="{Cd}"/>
                    <ObjectAttribute title="Discription" text="{Desc}" binding="{SalesDescription}"/>
                </attributes>
            </ObjectListItem>
        </items>
    </List>
</content>