Skip to content
Advertisement

Bind Association XSOData in UI5?

Let’s say I have Employee entity associated with Address entity in XSOData and I want to bind them to a single control – StandardListItem. How to achieve this?

<List id="EmployeeList" headerText="Employees" items="{ path: '/Employee'}">
  <items>
    <StandardListItem title="{Name}" //from Employee entity
                      description="{Address/City}" //from Address entity
    />
  </items>
</List>

Associated address details available at Employee('emp1')/Address/

TIA.

Advertisement

Answer

If I understand correctly, the Address element is an entity. You cannot bind a property to a whole entity. I would assume that it has some properties of its own (e.g. Street, City, etc.). You have to bind the UI5 control property to either a single property of the OData entity or use a formatter / expression binding to combine them together.

Nevertheless, you will anyway have to slightly adjust your code. The related Address is not retrieved by default when you do the binding as you have. To retrieve it, you should use the $expand option.

<List id="EmployeeList" headerText="Employees" 
    items="{path: '/Employee', parameters: {expand: 'Address'}}">
    <items>
        <StandardListItem title="{Name}"
                  description="{Address/SomePropertyFromTheAddressEntity}"
        />
    </items>
</List>
Advertisement