现在的位置: 首页 > 综合 > 正文

2012年06月18日 ⁄ 综合 ⁄ 共 1532字 ⁄ 字号 评论关闭

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">

http://www.manfridayconsulting.it/index.php?option=com_content&view=article&id=42:datagrid-binded-to-httpservice&catid=12:flex-3&Itemid=27

DataGrid binded to HTTPService
Lunedì 26 Gennaio 2009 20:23
How to consume an HTTPService using Xml Object. You can see the power of Databinding in this environment.
You only need to set the property dataProvider="{productsarray}" of the DataGrid to get all objects coming from
on results function.
 
Here an example of Xml object definition 
<dataroot>
<product>
<id>1</id>
<total>2</total>
<name>Motherboard</name>
<price>100</price>
</product>
<product>
<id>2</id>
<total>2</total>
<name>Pprocessor</name>
<price>150</price>
</product>
</dataroot>
 
Now we start with the sample application:  
 
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
creationComplete="initApp()">
<mx:HTTPService id="srv" url="services/products.xml"
resultFormat="object"
result="onResult(event)"/>
<mx:DataGrid id="grid"
width="100%"
height="100%"
dataProvider="{productsarray}">
<mx:columns>
<mx:DataGridColumn headerText="Total No."
dataField="total"/>
<mx:DataGridColumn headerText="Name"
dataField="name"/>
<mx:DataGridColumn headerText="Price"
dataField="price"/>
</mx:columns>
</mx:DataGrid>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var productsarray:ArrayCollection;
private function initApp():void {
this.srv.send();
}
private function onResult(evt:ResultEvent):void {
this.productsarray = evt.result.data.product;
}
]]>
</mx:Script>
</mx:Application>

抱歉!评论已关闭.