Why can I give items as property?

不想你离开。 提交于 2020-01-25 07:39:25

问题


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?


回答1:


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.




回答2:


Writing "items=..." in the XML is the same as writing "bindItems(..." or "bindAggregation('items',..." in JS. The framework knows that it is an aggregation and that you are binding the path '/ProductCollection' from your unnamend odata model to it.

As Ronnie mentioned, in the binding there are properties like 'path' or 'sorters'. You can check it here https://sapui5.hana.ondemand.com/#/api/sap.ui.base.ManagedObject/methods/bindAggregation The object oBindingInfo is the one.



来源:https://stackoverflow.com/questions/51095315/why-can-i-give-items-as-property

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!