<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
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>
|