今天做东西,就又绕到一个很原始的问题,Array 和 ArrayCollection有什么区别,在网上找到了这样一个例子,很有帮助,先贴出来,以后再有新的理解,就再说呗。
原文地址:http://hi.baidu.com/tokios/blog/item/aeb5cd1b4b974bfeaf513384.html
ArrayCollection实现了ICollectionView接口,在Flex的类定义内属于[数据集],他提供更强大的检索、过滤、排序、分类、更新监控等功能。类似的还有XMLListCollection
这两者差别在于如果用array在作为data provider绑定于控件上,就无法获得控件的更新,除非控件被重新绘制或者data provider被重新指定,而Collection则是将array的副本存储于Collection类的某个对象之中,其特点是Collection类本身就具备了确保数据同步的方法,例子如下(取自adobe内部工程师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;
public function addCountryToArra(country:String):void{
myArray.push(country);
}
public function addCountryToCollection(country:String):void{
myCollection.source=myArray;
myCollection.addItem(country);
}
]]>
</mx:Script>
<mx:TextInput id="countryTextInput" text="广州"/>
<mx:Label text="Bound to Array (Raw Object)"/>
<mx:Button click="addCountryToArra(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>
总结:
当Array的数据发生变化的时候,用它作为数据源的控件不能感知这种变化。 例如:myArray.push("new"); 这时,如果一个List用它作为dataProvider,List的列表中不会增加新加入的这个值。如要改变,得重新给控件赋值。
而当ArrayCollection的数据发生变化的时候,能够通知控件发生变化。 例如:myArrayCollection.addItem("new"); 这时,如果一个控件List用它作为dataProvider,List列表中会增加一列内容.
|
分享到:
相关推荐
Flex的Array和ArrayCollection
Flex的ArrayCollection在某些情况无法绑定解决方法
ArrayCollection求最大值,最小值,排序。供大家共同学习一下。
因为new ArrayCollection 需要 array对象,event.result是空间返回对象(JAVA方法返回值)所以类型不同无法使用new 构造ArrayCollection ,可是恶心的FLEX偏偏支持javalist=ArrayCollection
NULL 博文链接:https://xaajie.iteye.com/blog/379054
NULL 博文链接:https://tangdonglai.iteye.com/blog/1478277
tree多数情况下操作xml比较方便,而本人却对xml有些排斥,说得更确切些,对xml用的不是那么得心应手,所以选择了ArrayCollection
ArrayCollection添加过滤器后,调用removeItemAt()是无法删除的,下面有个不错的解决方法,大家可以参考下
as3xls 只支持excel2003版本以下的,不支持扩展名为.xlsx的excel,而类库Rxlsx支持....var datasource:ArrayCollection = new ArrayCollection(sheet); //可转换为ArrayCollection,用于表格控件grid绑定数据显示出来
as3xls 只支持excel2003版本以下的,不支持扩展名为.xlsx的excel,而类库Rxlsx支持....var datasource:ArrayCollection = new ArrayCollection(sheet); //可转换为ArrayCollection,用于表格控件grid绑定数据显示出来
Design 视图:按钮,图片 Source 视图 MXML/ActionScript 3.0 动态效果:移动,旋转,放大,淡入...表格DataGrid, dataProvider,集合对象Array,ArrayCollection Http请求 HttpService, 报表:饼图,折线图,柱状图
flex外部读取xml
最近研究FLEX,在网上看过100遍同一篇文章,结果测试不通,不知道到底能不能跑通,最后翻资料自己试验处理。
1.该图表的数据源为ArrayCollection类型的arrayC 2.每增加一条线,其实就是增加一个数据源中的ArrayCollection每个对象的一个属性,且属性名不能重复 3.修改ArrayCollection后,同时修改LineChart的series
2. var bar:ArrayCollection = new ArrayCollection(); 3. for each ( var i:Object in ac ){ 4. bar.addItem( i ); 5. } 6. // fantastic ! // 7. var bar:ListCollectionView = new ListCollectionView( ...
使用Object对XML和ArrayCollection之间的转换,包括9种图形集合,简单样式及效果。物有所值,绝对可以运行。
import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var slides:ArrayCollection private function resultHandler(event:ResultEvent):void ...
import mx.collections.ArrayCollection; import mx.rpc.events.ResultEvent; [Bindable] private var slides:ArrayCollection private function resultHandler(event:ResultEvent):void ...
flex通过httpService读取xml数据到datagird中,通过读取远程URL的XML数据(这里保存到本地),保存到ArrayCollection中,然后在将ArrayCollection绑定到datagird上 环境:flex3.0 可直接运行