简体   繁体   English

Flex 4以编程方式将项目添加到<s:List>

[英]Flex 4 Programatically Add Item to <s:List>

How can I add an item to a Flex 4 <s:List> component that has an item renderer? 如何将项目添加到具有项目渲染器的Flex 4 <s:List>组件中? 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. <s:List>绑定到的data变量将具有与我要附加在列表上的对象完全相同的属性。

Please let me know if I can provide any more details. 如果可以提供更多详细信息,请告诉我。

Thank you for your time. 感谢您的时间。

How can I add an item to a Flex 4 component that has an item renderer? 如何将项目添加到具有项目渲染器的Flex 4组件中?

You wouldn't. 你不会的 You would add an item to the List's dataProvider. 您可以将一个项目添加到列表的dataProvider中。 Then the list decides how to display the elements in the dataProvider based on other factors, such as the layout and the itemRenderer. 然后,列表根据其他因素(例如布局和itemRenderer)决定如何在dataProvider中显示元素。 For visual purposes, one way to view the list is as a collection of itemRenderers. 出于视觉目的,查看列表的一种方法是作为itemRenderers的集合。 There is one itemRenderer for each displayed item in the list. 列表中每个显示的项目都有一个itemRenderer。

In most cases there will be fewer items displayed in the list than there are items in the dataProvider. 在大多数情况下,列表中显示的项目少于dataProvider中的项目。 itemRenderers are re-used as the list is scrolled through, and the data property on the itemRenderer instance is modified. 滚动列表时将重新使用itemRenderers,并修改itemRenderer实例上的data属性。

So, if you want to know how to add an item to a List's dataProvider, it depends on the dataProvider type. 因此,如果您想知道如何将项目添加到列表的dataProvider,则取决于dataProvider类型。 Assuming an ArrayCollection, you should do something like this: 假设使用ArrayCollection,则应执行以下操作:

this.data.addItem(myNewItem);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM