您的位置:首页 > 理论基础 > 计算机网络

flex通过httpService获取远程XML数据,并显示到DATAGIRD上

2009-12-03 11:16 579 查看
mxml:

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>222222</store_telephone>
<store_address>ttttttttt</store_address>
<book id="1" category="Web 开发">
<bookname>Getting Start with Flex</bookname>
<sprice>49.9</sprice>
<sale>45.9</sale>
</book>
</store>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息