Search code examples
odatasapui5

UI5 Object Attributes with Multiple Associations


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)?


Solution

  • Can you try this?. I am setting the binding context using the 'binding' attribute. I am assuming that SalesList to SalesDescription is a 1:1 relationship. (Association). Also 'SalesDescription' is the name of the navigation property .

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