读书人

mx跟spark中dataProvider的差异

发布时间: 2012-09-20 09:36:51 作者: rapoo

mx和spark中dataProvider的差异
public function set dataProvider(value:Object):void { if (collection) { collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler); } if (value is Array) { collection = new ArrayCollection(value as Array); } else if (value is ICollectionView) { collection = ICollectionView(value); } else if (value is IList) { collection = new ListCollectionView(IList(value)); } else if (value is XMLList) { collection = new XMLListCollection(value as XMLList); } else if (value is XML) { var xl:XMLList = new XMLList(); xl += value; collection = new XMLListCollection(xl); } else { // convert it to an array containing this one item var tmp:Array = []; if (value != null) tmp.push(value); collection = new ArrayCollection(tmp); }}

?、

? 从上面的代码可以看到列表组件支持的数据类型有Array、ICollectionView、XMLListCollection、ArrayCollection等。

?

?在spark中,dataProvider类型必须是IList类型。 ArrayList, AsyncListView, ListCollectionView 类实现了IList接口,但是Array类没有实现IList接口,因此在sprak中Array就不能做为列表组件的数据源。

?

?ArrayList 类是使用后备 Array 作为数据源的 IList 的一个简单实现,也就是说,它比ArrayCollection更轻量级,想ArrayCollection具备的过滤,排序等功能,ArrayList是不具备的。如果您用不到ArrayCollection的一些复杂功能,可以使用ArrayList来获取更好的执行效率。

??

读书人网 >Web前端

热点推荐