Flex基础-----之Flex中Array和ArrayCollection的区别
2010-08-25 10:45
309 查看
当Array的数据发生变化的时候,用它作为数据源的控件不能感知这种变化。
例如:myArray.push("new value"); 这时,如果一个List用它作为dataProvider,List的列表中不会增加新加入的这个值。
而当ArrayCollection的数据发生变化的时候,能够通知控件发生变化。
例如:myArrayCollection.addItem("new item"); 这时,如果一个控件List用它作为dataProvider,List列表中会增加一列内容。
=================================================================
ArrayCollection实现接口ICollectionView,在Flex的类定义内属于[数据集],他提供更强大的检索、过滤、排序、分类、更新监控等功能。FDK2提供的类似的类还有XMLListCollection
这两者差别在于如果用array在作为data provider绑定于control之上,就无法获得控件的更新,除非控件被重新绘制或者data provider被重新指定,而Collection则是将array的副本存储于Collection类的某个对象之中,其特点是Collection 类本身就具备了确保数据同步的方法,例子如下(取自ad obe内部工程师training示例,稍有改变)
例如:myArray.push("new value"); 这时,如果一个List用它作为dataProvider,List的列表中不会增加新加入的这个值。
而当ArrayCollection的数据发生变化的时候,能够通知控件发生变化。
例如:myArrayCollection.addItem("new item"); 这时,如果一个控件List用它作为dataProvider,List列表中会增加一列内容。
=================================================================
ArrayCollection实现接口ICollectionView,在Flex的类定义内属于[数据集],他提供更强大的检索、过滤、排序、分类、更新监控等功能。FDK2提供的类似的类还有XMLListCollection
这两者差别在于如果用array在作为data provider绑定于control之上,就无法获得控件的更新,除非控件被重新绘制或者data provider被重新指定,而Collection则是将array的副本存储于Collection类的某个对象之中,其特点是Collection 类本身就具备了确保数据同步的方法,例子如下(取自ad obe内部工程师training示例,稍有改变)
<?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=["北京","上海","深圳"]; [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>
相关文章推荐
- FLEX Array和ArrayCollection的区别
- Flex中Array,ArrayList,ArrayCollection的区别
- flex数据基础 array和arraycollection
- Flex学习笔记:ArrayCollection和Array的区别
- Flex中ArrayCollection与Array的区别
- Flex的Array和ArrayCollection的用法和区别
- Flex的Array和ArrayCollection
- Flex——Array,ArrayCollection,Vector性能比较
- Flex 遍历 ArrayCollection, Array
- Flex——Array,ArrayCollection,Vector性能比较
- Flex 遍历 ArrayCollection, Array
- Array与ArrayCollection的区别
- 基础知识系列☞C#中数组Array、ArrayList和List三者的区别
- Linux shell 数组array基础【${a[*]}和$a的区别】
- Flex 遍历 ArrayCollection, Array
- Flex之旅:第一部分:flex必备基础知识积累(4)---ArrayCollection, Array赋值写法
- ArrayCollection和Array的区别
- Flex Array和Flex ArrayCollection的用法和区别
- java基础之Collection与Collections和Array与Arrays的区别
- C#数组Array的基础知识及二位数组和数组的数组的区别