`

Flex XML转ArrayCollection

    博客分类:
  • Flex
阅读更多

mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
	<mx:Script>
		<![CDATA[
		import mx.collections.ArrayCollection;
		import mx.rpc.events.ResultEvent;
		import mx.utils.ObjectProxy;
		
		[Bindable]
		private var list:ArrayCollection=new ArrayCollection();
		
		private function resultHandler(event:ResultEvent):void {		
			if(event.result.store.book is ObjectProxy){
				list.removeAll();
				list.addItem(event.result.store.book);
			}
			else
				list=event.result.store.book;
				
			booksGrid.dataProvider=list;
		}
		
		]]>
	</mx:Script>
	<mx:HTTPService id="booksXML" url="data/book_store.xml" showBusyCursor="true" result="resultHandler(event)"/>
	
	<mx:Button label="读取资料" click="this.booksXML.send()"/>
	<mx:DataGrid id="booksGrid" width="600" height="400">
		<mx:columns>
			<mx:DataGridColumn headerText="编号" dataField="id" width="30"/>
			<mx:DataGridColumn headerText="书名" dataField="bookname"/>
			<mx:DataGridColumn headerText="分类" dataField="category" width="80"/>
			<mx:DataGridColumn headerText="售价" dataField="sprice" width="60"/>
			<mx:DataGridColumn headerText="特价" dataField="sale" width="60"/>
		</mx:columns>
	</mx:DataGrid>
</mx:Application> 
 

xml:

 

<?xml version="1.0" encoding="utf-8"?>
<store>
  <store_title>我的书店</store_title>
  <store_telephone>0411-12345678</store_telephone>
  <store_address>大连市高新园区新华路60号</store_address>
  <book id="1" category="Web 开发">
    <bookname>Getting Start with Flex</bookname>
    <sprice>49.9</sprice>
    <sale>45.9</sale>
  </book>
</store>
 
分享到:
评论
2 楼 jonnnn 2010-11-09  
HTTPService 本身已经给你转了哦,如果返回的是String类型已该怎么转
1 楼 jonnnn 2010-11-09  
正需..........

相关推荐

Global site tag (gtag.js) - Google Analytics