Flex, Array, ArrayList, ArrayCollection difference

 

一、     

    Array of data when the time changes, use it as a data sourcecontrol can not perceive this change. 
For example: myArray.push ("new value"); then, if a List to use it as dataProvider, List does not increase the list of newlyadded this value. 
When the ArrayCollection when the data changes, to notify the control to change. 
For example: myArrayCollection.addItem ("new item"); then, if a List control, use it as dataProvider, List list, a list of content will increase.   

  当Array的数据随着时间发生变化的时候,用它作为数据源的组件无法感知这种变化。例如:myArray.push ("new value");  利用push方法向Array中添加一新的数据,如果一个List列表组件用它作为数据源,List不会增加刚刚添加的这个数据。

     而对于ArrayCollection, 当数据发生变化,会通知相应的组件变化。例如:myArrayCollection.addItem ("new item"); ,那么,如果List用它作为数据源,则List列表的内容会增加。

二、

      ArrayCollection implements the interface ICollectionView, the definition in the Flex class is [data set], he provided a more powerful search, filtering, sorting, classification, updating monitoring. FDK2 class also provides similar XMLListCollection. 
     This difference between the two is that if the array as the data provider with binding in control over, you can not get control of the update, unless the control is repainted or the data provider is reassigned, a copy of the Collection sucked array stored in the Collection class into an object, which is characterized Collection class itself has the means to ensuredata synchronization in the Flex 4 introduces a new data type: ArrayList. It implements the IList interface, the bottom of the Array as a data source. Essentially it is a lightweight ArrayCollection, can be used as a data source bound to the control. ArrayCollection but the difference is, it can not filter and filter data. Note that, based on the list of Spark control is not directly to Array as data provider, we must implement IList interface. It should also be the introduction of one of the reasons ArrayList data type 。

      ArrayCollection 实现了ICollectionView接口,它在FLEX中被定义为数据集。他提供了更加强大的搜索,过滤,排序,分类,更新监控等功能。FDK2类也提供了类似的XMLListCollection类。两者的不同点在于,array作为数据源与控件绑定的时候,不会得到控件的更新,除非控件被重绘或者数据源被重新分配,这时候,存储在Collection类的一个array的拷贝会变成一个对象,因此Collection类具有一个特点就是能够处理“数据同步”。在FLEX4中产生了一种新的数据类型ArrayList.

    ArrayList实现了IList 接口,底部用Array用为数据源。本质上,ArrayList是一个轻量级的ArrayCollection。可以用来作为数据源绑定到控件上,与ArrayCollection的不同是,它不能过滤数据。需要注意的是,基于Spark 的控件列表,不能直接用Array用为数据源,必须实现IList接口,这应该也是一种新的数据类型ArrayList 产生的原因之一。

三、程序举例 

  <? Xml version = "1.0" encoding = "utf-8"?>
 <mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml">
 <mx:Script>
 <! [CDATA [
  import mx.collections.ArrayCollection;
 
[Bindable]
  public var myArray: Array = ["Beijing", "Shanghai", "Shenzhen"];
  [Bindable]
  public var myCollection: ArrayCollection = new ArrayCollection (myArray);
  
  public function addCountryToArray (country: String): void {
      myArray.push (country);
  }
  public function addCountryToCollection (country: String): void {
      myCollection.addItem (country);
  }
 ]]>
 </ Mx: Script>
  <mx:TextInput id="countryTextInput" text="广州"/> 


  <mx:Label text="Bound to Array (Raw Object)"/>
  <mx:Button click="addCountryToArray(countryTextInput.text)" label="Add Country to Array"/>
  <mx:List dataProvider="{myArray}" width="200"/>   


  <mx:Label text="Bound to Collection"/>
  <mx:Button click="addCountryToCollection(countryTextInput.text)" label="Add Country to Collection"/>
  <mx:List dataProvider="{myCollection}" width="200"/>
 </ Mx: Application>

 

ArrayList应用

  <? Xml version = "1.0" encoding = "utf-8"?>
 <S: Application xmlns: fx = "
http://ns.adobe.com/mxml/2009"    xmlns: s = "library: / / ns.adobe.com / flex / spark"     xmlns: mx = "library: / / ns.adobe.com / flex / mx"        minWidth = "955" minHeight = "600">
    <fx:Declarations>
     
<s:ArrayList id="al">
       <fx:Object type="Line" class="LineSeries"/>
       <fx:Object type="Mountain" class="AreaSeries"/>
       <fx:Object type="Candlestick" class="CandlestickSeries"/>
        <fx:Object type="HLOC" class="HLOCSeries"/>
     </ S: ArrayList>
 </ Fx: Declarations>
 <S: DropDownList dataProvider = "{al}"    labelField = "type" selectedIndex = "0" />
 </ S: Application>

   

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值