Array属性raw data object,不能保持同步,方式有限,Collection更好
Data provider分两种Linear和Hierarchical
Linear用IList ICollectionView操作,
Hierarchical用data descriptor来操作
Collection作为data provider时
更新可以立即可见,而不需要refresh
可以处理远程的data provider
single provider to multiple components
一些组件会自动的把Array转换成Collection
HttpServices, WebServices返回Array, RemoteObject返回ArrayCollection
Sort:
创建一个Sort对象,设置SortField, 设置Collection对象的Sort属性,refresh()
Filter:
创建一个单对象参数函数,返回Boolean值,设置Collection对象的filterFunction属性
IViewCursort:
设置
public var myCursor:IViewCursor;
myCursor=myAC.createCursor();
遍历
while (! myCursor.afterLast) {
myCursor.moveNext();
}
查找(绝对查找)
myCursor.findFirst("MZ");
myCursor.findFirst({label:"ME"})
myCursor.findFirst({label:"ME", data:"Augusta"});
相对查找seek()
Bookmarks
var myBookmark:CursorBookmark=myIViewCursor.bookmark;
myIViewCursor.seek(myBookmark);collection events:
实现IList, ICollectionView的类dispatch CollectionEvents,它们有itemUpdated来告诉Collections更新已经完成。
Listener为reservationsChanged,event的kind属性:ADD REMOVE, UPDATE, RESET
ICollectionView中用enableAutoUpdate()和disableAutoUpdate()来控制自动更新
[Bindable]可以加在类或属性前,则此类或属性改变时会产生propertyChange事件
Hierarchial Data Provider
两种:
XML: well-formed XML, XML, XMLList, XMLListCollection Object, <mx:XML>, <mx:XMLList>
Object: 具有children field的Object, <mx:Model>
<mx:XML>产生一个XML或XMLNode对象,默认为e4x格式,可设成xml
(好象<mx:XML>和<mx:XMLList>的不同在于,<mx:XML>后紧跟<root>)
An XMLList object is an ordered collection of properties. An XMLList object represents an XML document, an XML fragment, or an arbitrary collection of XML objects.
An XMLList object with one XML element is treated the same as an XML object. When there is one XML element, all methods that are available for the XML object are also available for the XMLList object.
用data descriptor来到处理
ITreeDataDescriptor处理tree
IMenuDataDescriptor处理Menu一类
当使用XML用data provider时,如果需要动态更新,则要转换成XMLListCollection:
<mx:XMLListCollection source="{XMLOBJECT.NODE}"/>
设成Tree的dataProvider时,需要设置labelField属性,showRoot属性可选
<mx:Tree dataProvider="{capitalColl}" labelField="@label" width="300"/>
如果Server端的类型为List,RemoteObejct返回ArrayCollection
public var ds:DataService;
[Bindable]
public var contacts:ArrayCollection = new ArrayCollection
ds = new DataService("ServiceName");
ds.fill(contacts);
不断获取的叫paged data,没有获取到的是pending data,这个机制用来缓解server和带宽压力
Data provider分两种Linear和Hierarchical
Linear用IList ICollectionView操作,
Hierarchical用data descriptor来操作
Collection作为data provider时
更新可以立即可见,而不需要refresh
可以处理远程的data provider
single provider to multiple components
一些组件会自动的把Array转换成Collection
HttpServices, WebServices返回Array, RemoteObject返回ArrayCollection
Sort:
创建一个Sort对象,设置SortField, 设置Collection对象的Sort属性,refresh()
Filter:
创建一个单对象参数函数,返回Boolean值,设置Collection对象的filterFunction属性
IViewCursort:
设置
public var myCursor:IViewCursor;
myCursor=myAC.createCursor();
遍历
while (! myCursor.afterLast) {
myCursor.moveNext();
}
查找(绝对查找)
myCursor.findFirst("MZ");
myCursor.findFirst({label:"ME"})
myCursor.findFirst({label:"ME", data:"Augusta"});
相对查找seek()
Bookmarks
var myBookmark:CursorBookmark=myIViewCursor.bookmark;
myIViewCursor.seek(myBookmark);collection events:
实现IList, ICollectionView的类dispatch CollectionEvents,它们有itemUpdated来告诉Collections更新已经完成。
Listener为reservationsChanged,event的kind属性:ADD REMOVE, UPDATE, RESET
ICollectionView中用enableAutoUpdate()和disableAutoUpdate()来控制自动更新
[Bindable]可以加在类或属性前,则此类或属性改变时会产生propertyChange事件
Hierarchial Data Provider
两种:
XML: well-formed XML, XML, XMLList, XMLListCollection Object, <mx:XML>, <mx:XMLList>
Object: 具有children field的Object, <mx:Model>
<mx:XML>产生一个XML或XMLNode对象,默认为e4x格式,可设成xml
(好象<mx:XML>和<mx:XMLList>的不同在于,<mx:XML>后紧跟<root>)
An XMLList object is an ordered collection of properties. An XMLList object represents an XML document, an XML fragment, or an arbitrary collection of XML objects.
An XMLList object with one XML element is treated the same as an XML object. When there is one XML element, all methods that are available for the XML object are also available for the XMLList object.
用data descriptor来到处理
ITreeDataDescriptor处理tree
IMenuDataDescriptor处理Menu一类
当使用XML用data provider时,如果需要动态更新,则要转换成XMLListCollection:
<mx:XMLListCollection source="{XMLOBJECT.NODE}"/>
设成Tree的dataProvider时,需要设置labelField属性,showRoot属性可选
<mx:Tree dataProvider="{capitalColl}" labelField="@label" width="300"/>
如果Server端的类型为List,RemoteObejct返回ArrayCollection
public var ds:DataService;
[Bindable]
public var contacts:ArrayCollection = new ArrayCollection
ds = new DataService("ServiceName");
ds.fill(contacts);
不断获取的叫paged data,没有获取到的是pending data,这个机制用来缓解server和带宽压力