dataprovider tag is working in flex

118 Views Asked by At

hai i m new in flex and was trying example but getting nothing

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="bookData.send()">
<mx:HTTPService id="bookData" url="/assets/books.xml"/>
<mx:DataGrid x="56" y="250" width="950" dataProvider= "{bookData.lastResult.books.stock}"/>
</mx:Application>

Above is my mxml file here is my books.xml

<?xml version="1.0" encoding="iso-8859-1"?>
<books>
<stock>
<name>The Picasso Code</name>
<author>Dan Blue</author>
<category>Fiction</category>
<description>Cubist paintings reveal a secret society of people who really look like that</description>
</stock>
<stock>....

i think i m doing something wrong in dataprovider tag reason is when i use

dataProvider = "{d}"

it return datagrid with object

2

There are 2 best solutions below

0
On

The dataprovider must be your HttpService bookData's resultEvent's stock. You should use result event in the HttpService tag. For example,

<mx:HTTPService id="bookData" url="/assets/books.xml" result="contentHandler(event)"/>   

            import mx.rpc.events.ResultEvent;  
            [Bindable] private var xmlListData:XMLList; 
            private function contentHandler(evt:ResultEvent):void{  
                xmlListData= evt.result.stock;
            } 

<mx:DataGrid x="56" y="250" width="950" dataProvider= "{xmlListData}"/>
0
On

what I'm missing in your code is the url-request vor your xml. Databindung and Dataprovider needs an eventbases communication whenever new data are called from backend, so also the first time.

What you need is to convert your xml from backend to a xmlCollection. Make the var Bindable. The name of your bindable XMLXollection is your Dataprovider.

BR Frank