从两个blog中获取的信息
//////信息1 start
当Array的数据发生变化的时候,用它作为数据源的控件不能感知这种变化。
例如:myArray.push("new value"); 这时,如果一个List用它作为dataProvider,List的列表中不会增加新加入的这个值。
而当ArrayCollection的数据发生变化的时候,能够通知控件发生变化。
例如:myArrayCollection.addItem("new item"); 这时,如果一个控件List用它作为dataProvider,List列表中会增加一列内容.
例如:myArray.push("new value"); 这时,如果一个List用它作为dataProvider,List的列表中不会增加新加入的这个值。
而当ArrayCollection的数据发生变化的时候,能够通知控件发生变化。
例如:myArrayCollection.addItem("new item"); 这时,如果一个控件List用它作为dataProvider,List列表中会增加一列内容.
///////信息1 end
///////信息2 start
今天看到这么一篇帖子,但是我对他的正确性表示怀疑。
因为,我就是用Array做的dataProvider,效果是可以得到更新的。
Array和ArrayConllection做dataProvider,做VO,各有优缺点,相比之下
我还是选择了Array。
因为
1)取数组下标的应用要比让数组扩展的应用更多
2)后台JavaBean也用的是数组[]
3)for循环数组似乎比for each ArrayConllection看起来更“傻瓜化”
4)给Array数组扩展长度,也可以变通实现,而且代价并不大
今后如果有更进一步研究,再来贴。
转帖部分如下:
ArrayCollection 实现接口 ICollectionView,在 Flex 的类定义内属于[数据集],他提供更强大的检索、过滤、排序、分类、更新监控等功能。FDK2提供的类似的类还有 XMLListCollection
这两者差别在于如果用 array 在作为 data provider 绑定于 control 之上,就无法获得控件的更新,除非控件被重新绘制或者 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(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>
因为,我就是用Array做的dataProvider,效果是可以得到更新的。
Array和ArrayConllection做dataProvider,做VO,各有优缺点,相比之下
我还是选择了Array。
因为
1)取数组下标的应用要比让数组扩展的应用更多
2)后台JavaBean也用的是数组[]
3)for循环数组似乎比for each ArrayConllection看起来更“傻瓜化”
4)给Array数组扩展长度,也可以变通实现,而且代价并不大
今后如果有更进一步研究,再来贴。
转帖部分如下:
ArrayCollection 实现接口 ICollectionView,在 Flex 的类定义内属于[数据集],他提供更强大的检索、过滤、排序、分类、更新监控等功能。FDK2提供的类似的类还有 XMLListCollection
这两者差别在于如果用 array 在作为 data provider 绑定于 control 之上,就无法获得控件的更新,除非控件被重新绘制或者 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(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>
///////信息2 end