Flex 根据ArrayCollection的实现IViewCursor接口类来遍历HTTPService的获得的数据

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="startService()"
xmlns="*" xmlns:productsView="productsView.*">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
import mx.collections.IViewCursor;
import samples.flexstore.Product;

[Bindable]
        private var catalog:ArrayCollection;


private function startService():void{
productService.send();
}


private function productServiceResultHandler(event:ResultEvent):void{

var products:ArrayCollection = event.result.catalog.product;
// 定义一个临时ArrayCollection对象
            var temp:ArrayCollection = new ArrayCollection();
//             创建使用此视图的新 IViewCursor。 返回 IViewCursor — 新的 IViewCursor 实现。 
            var cursor:IViewCursor = products.createCursor();
//             如果将光标定位于视图中最后一个项目之后,则此属性为 true。
            while (!cursor.afterLast)
            {
                var product:Product = new Product();
//                current 属性    可以访问位于此光标引用的源集合中的位置的对象。
                product.fill(cursor.current);
                temp.addItem(product);
//                 moveNext():Boolean  将光标移动到集合中的下一个项目。
                cursor.moveNext();
            }
           catalog = temp;
}
]]>
</mx:Script>
<mx:HTTPService id="productService" url="data/catalog.xml" result="productServiceResultHandler(event)"/>
<mx:VBox x="10" y="10" height="620" width="994">
<mx:ApplicationControlBar width="100%">
<mx:Image/>
<mx:ToggleButtonBar height="100%" dataProvider="{storeViews}" styleName="storeButtonBar">
</mx:ToggleButtonBar>
</mx:ApplicationControlBar>
<mx:ViewStack id="storeViews" width="100%" height="100%">
<mx:Canvas label="View 1" width="100%" height="100%">
<mx:Button label="nihao1"/>
</mx:Canvas>
<ProductsView1/>
<mx:Canvas label="View 1" width="100%" height="100%">
<mx:Button label="nihao3"/>
</mx:Canvas>
</mx:ViewStack>
</mx:VBox>

</mx:Application>

你可能感兴趣的:(xml,Flex)