[ALOY-647] Allow complex data binding on ListView for sections and items
GitHub Issue | https://github.com/tidev/alloy/issues/1311 |
---|---|
Type | Improvement |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Models, XML |
Labels | n/a |
Reporter | Tony Lukasavage |
Assignee | Unknown |
Created | 2013-05-01T15:53:35.000+0000 |
Updated | 2018-10-27T20:32:20.000+0000 |
Description
problem
As per ALOY-609, ListSection is the UI component which is in charge of automatically populating a ListView with ListItems via a data bound model or collection. So the dataCollection needs to be set at the
<ListView id="list" defaultItemTemplate="title">
<Templates>
<ItemTemplate name="fullItem" height="70">
<ImageView bindId="image" class="image"/>
<Label bindId="title" class="title text-and-image"/>
<Label bindId="subtitle" class="subtitle text-and-image"/>
</ItemTemplate>
<ItemTemplate name="titleAndSub" height="70">
<Label bindId="title" class="title"/>
<Label bindId="subtitle" class="subtitle"/>
</ItemTemplate>
<ItemTemplate name="title" height="50">
<Label bindId="title" class="title"/>
</ItemTemplate>
</Templates>
<ListSection id="section" dataCollection="info" dataTransform="doTransform">
<ListItem template="{template}" title:text="{title}" subtitle:text="{subtitle}" image:image="{image}"/>
</ListSection>
</ListView>
It would be nice to be able to support complex collections, or multiple collections, in order to be able to create a section/item structure directly from a complex data model. Off the top of my head, there's probably 2 ways this can be achieved.
proposed solution A
Resolving ALOY-614 would allow developers to use dynamically defined *dataCollection* XML attributes in their views. This would in turn allow you to define a data bound collection as a result of a prior dataCollection. For example:
<ListView id="list" defaultItemTemplate="title" dataCollection="someCollection">
<Templates>
<!-- define templates here as usual -->
</Templates>
<ListSection id="section" headerTitle="{title}" dataCollection="{nestedCollectionFromSomeCollection}">
<ListItem template="{template}" title="{title}"/>
</ListSection>
</ListView>
proposed solution B
Develop a distinct convention for structuring of complex data such that it can all be handled internally by Alloy and the structure is just created automatically. For example, this pseudo-model shows a convention we might create in order for a
{
viewProp: 'just some property at the ListView level'
sections: [
{
title: 'some title, would be bound to this instance of ListSection'
items: [
{
title: 'another title, would be bound to this instance of ListItem in the containing ListSection',
template: 'someTemplate'
},
// ...
]
},
// ...
]
and the above pseudo-model would be leveraged in XML as such to create a section for each entry in the *sections* array, and an item for each entry in that section's *items* array.
<ListView id="list" defaultItemTemplate="title" dataCollection="thePseudoModel">
<Templates>
<!-- define templates here as usual -->
</Templates>
<ListSection id="section" headerTitle="{title}">
<ListItem template="{template}" title="{title}"/>
</ListSection>
</ListView>
This will be great.
This would be a good addition. Right now we have to write JS whenever we need to construct dynamic ListSection headers.