Search code examples
sapui5

Why can I give items as property?


The Table is extended from the ListBase. On the Table, I can you use items aggregation from ListBase as a property like as following:

<Table inset="false" items="{ path: '/ProductCollection', sorter: { path: 'Name' } }">    

Why can I use items as a property, although is defined as aggregation?


Solution

  • In UI5, there are basically two ways of filling an aggregation. One is by adding the elements directly, and the other is to bind them to a model.

    Your example shows the latter case, where the items aggregation is bound to the collection /ProductCollection in your model.

    An aggregation binding consists of two parts in XML views, one is the actual binding with the "property" as you did, and the other is to specify the "template" which is used for each element in the collection.

    This is also explained further in the documentation:

    <mvc:View
      controllerName="sap.ui.sample.App"
      xmlns="sap.m"
      xmlns:mvc="sap.ui.core.mvc">
      <List id="companyList" items="{/companies}">
        <items>
          <StandardListItem
            title="{name}"
            description="{city}"
          />
        </items>
      </List>
    </mvc:View>
    

    The List element has both an items attribute and a nested items element:

    • The attribute items="{/companies}" binds the children of our json model's companies array to the list. This by itself is not enough to display the companies, instead it sets the parent path for the binding of all contained list items and their descendants. In addition you need to declare a nested element.
    • The nested items element in our case contains a StandardListItem. This serves as a template for creating the individual list rows.