???? 在Flex中列表组件(DataGridBase, List, TileBase ),数据容器(DataGroup和SkinableDataContainer),都提供了dataProvider属性,我们可以将数据源绑定到这个属性上,让组件按照所需的格式来显示数据。
但是mx组件和spark组件所接受的dataProvider类型是不同的,mx的类型是Object,spark类型是IList。
??? mx中列表组件继承自ListBase类,如下代码是设置数据源的。
???
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来获取更好的执行效率。
??