现在的位置: 首页 > 综合 > 正文

Array 和 ArrayCollection 区别

2013年10月16日 ⁄ 综合 ⁄ 共 1409字 ⁄ 字号 评论关闭
今天看到这么一篇帖子,但是我对他的正确性表示怀疑。
因为,我就是用Array做的dataProvider,效果是可以得到更新的。
Array和ArrayConllection做dataProvider,做VO,各有优缺点,相比之下
我还是选择了Array。
因为
1)取数组下标的应用要比让数组扩展的应用更多
2)后台JavaBean也用的是数组[]
3)for循环数组似乎比for each  ArrayConllection看起来更“傻瓜化”
4)给Array数组扩展长度,也可以变通实现,而且代价并不大

今后如果有更进一步研究,再来贴。

转帖部分如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
  3.       <mx:Script>
  4.           <![CDATA[
  5.               import mx.collections.ArrayCollection;
  6.               [Bindable]
  7.               public var myArray:Array=["北京","上海","深圳"];
  8.               [Bindable]
  9.               public var myCollection:ArrayCollection=new ArrayCollection(myArray);
  10.               public function addCountryToArray(country:String):void{
  11.                   myArray.push(country);
  12.               }
  13.               public function addCountryToCollection(country:String):void{
  14.                   myCollection.addItem(country);
  15.               }
  16.           ]]>
  17.       </mx:Script>
  18.       <mx:TextInput id="countryTextInput" text="广州"/>
  19.       <mx:Label text="Bound to Array (Raw Object)"/>
  20.       <mx:Button click="addCountryToArray(countryTextInput.text)" label="Add Country to Array"/>
  21.       <mx:List dataProvider="{myArray}" width="200"/>
  22.       <mx:Label text="Bound to Collection"/>
  23.       <mx:Button click="addCountryToCollection(countryTextInput.text)" label="Add Country to Collection"/>
  24.       <mx:List dataProvider="{myCollection}" width="200"/>
  25. </mx:Application>

抱歉!评论已关闭.