Reputation: 17348
How can I add an item to a Flex 4 <s:List>
component that has an item renderer? Here is the code sample of the list that I would like to append data onto:
<s:List contentBackgroundAlpha="0" borderVisible="false" id="reviews"
itemRenderer="renderers.ReviewRenderer" dataProvider="{data}"
top="10" minHeight="1">
<s:layout>
<s:VerticalLayout useVirtualLayout="false" requestedMinRowCount="1" gap="35"/>
</s:layout>
</s:List>
The data
variable that the <s:List>
is bound to will have the exact same properties as the object that I would like to append on the list.
Please let me know if I can provide any more details.
Thank you for your time.
Upvotes: 0
Views: 1836
Reputation: 39408
How can I add an item to a Flex 4 component that has an item renderer?
You wouldn't. You would add an item to the List's dataProvider. Then the list decides how to display the elements in the dataProvider based on other factors, such as the layout and the itemRenderer. For visual purposes, one way to view the list is as a collection of itemRenderers. There is one itemRenderer for each displayed item in the list.
In most cases there will be fewer items displayed in the list than there are items in the dataProvider. itemRenderers are re-used as the list is scrolled through, and the data property on the itemRenderer instance is modified.
So, if you want to know how to add an item to a List's dataProvider, it depends on the dataProvider type. Assuming an ArrayCollection, you should do something like this:
this.data.addItem(myNewItem);
Upvotes: 1