PDA

View Full Version : populate list and combobox from xml


smakwam
08-17-2006, 03:57 PM
Hi all,
first time here so apologies for any mistakes ....
I am playing around with flex 2 and PHP. I have one page with a list box and a combo box on seperate panels. I am trying to populate both of these using a PHP backend which generates XML. The XML generation works beautifully as does the list box. My problem is that the combobox does not get populated, all i can see when running the app is [object Object] in the combobox !!!. the number of [object Object] match the number of items that are in the list box. I am sure it's a silly mistake on my part but being new to this I am not sure how to solve it. I have searched Google all day without success. Most of the examples hard code the array and if they do not, they use list boxes which is not what I am after. Perhaps there is no solution ....
Below is the mxml code.
Thanks in advance for any assistance you can provide.
Regards
Smakwam


/************************************************** *******
code start

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"

width="390" height="430"
creationComplete="bs.send();"
>
<mx:Script>

<![CDATA[
import mx.managers.CursorManager;
import mx.rpc.events.InvokeEvent;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;

[Bindable]
private var bloggersCol:ArrayCollection;

[Bindable]
private var bloggersCol2:ArrayCollection;

// Gets called when HTTPService is invoked to
// request the XML.
private function bsInvokeHandler(event:InvokeEvent):void

{
// Display the busy cursor
CursorManager.setBusyCursor();
}

// Gets called when the XML is successfully loaded.
private function bsResultHandler(event:ResultEvent):void

{
// Save a reference to the list of bloggers
bloggersCol = event.result.root.restaurant_category;

//bloggersCol2 = event.result.root.restaurant_category.name;
// Hide the busy cursor
CursorManager.removeBusyCursor();
}


private function bsFaultHandler(event:FaultEvent):void
{

// There was an error in loading the XML
Alert.show (event.fault.message);

// Hide the busy cursor
CursorManager.removeBusyCursor();
}
]]>

</mx:Script>

<!-- Service to load in XML -->
<mx:HTTPService
id="bs"
url="http://localhost/phpxml3.php"

invoke="bsInvokeHandler(event);"
result="bsResultHandler(event);"
fault="bsFaultHandler(event);"

/>

<mx:Panel title="Bloggers we love!" width="100%">
<mx:List
id="bloggersList" width="100%" rowCount="4"
dataProvider="{bloggersCol}"
labelField="name"
/>
<mx:ControlBar horizontalAlign="center">
<mx:Button
label="Add a blogger!"
click="bloggersCol.addItem({name:'Pete-Barr Watson', url:'http://petebarrwatson.com/'});"
/>
</mx:ControlBar>
</mx:Panel>

<!--<mx:ArrayCollection id="stateAC" source="{bloggersCol}"/> -->

<mx:Panel width="318" height="129" layout="absolute" title="Combo Box">
<mx:ComboBox x="10" y="10" width="278" id="cuisine" dataProvider="{bloggersCol}" >
</mx:ComboBox>
</mx:Panel>
</mx:Application>

/************************************************** ***

xnegvx
02-14-2007, 01:11 PM
Hey ...

Though it has been a long time since you posted it, I am facing the same problem. I am trying to populate the combobox with records returned by the database which are parsed by php into xml format. I can not get the combobox populated. If you know what can be the issue can you please let me know...

Cheers,
Kartik

dr_zeus
02-14-2007, 05:43 PM
Check the documentation for the ComboBox's labelField property. When you give it an object, it doesn't know what property should be used for the label.

Diavan
02-16-2007, 09:12 PM
// A literal XML string, returned by Webservice (e4x format), or created within the app.
var result:String = '<XMLList>
<Node name="foo" value="100"/>
<Node name="woo" value="200"/>
</XMLList>';

// Create an XML Object
var xmlObj:XML = new XML(result);

// Simply attach the above object to the Combobox dataprovider
cmbBox.dataProvider = xmlObj.Node;

// Above code should attach the XML tree with combo box.
// In order to display the 'name' in Combo box
cmbBox.labelField = "@name";

xnegvx
02-18-2007, 11:39 AM
Thanks Guys... Documentation 101 about combobox helped a lot .. specially label field as mentioned in earlier posts. Now I am a happy flexer (for now) .. :D

tetito
02-25-2008, 04:25 PM
// A literal XML string, returned by Webservice (e4x format), or created within the app.
var result:String = '<XMLList>
<Node name="foo" value="100"/>
<Node name="woo" value="200"/>
</XMLList>';

// Create an XML Object
var xmlObj:XML = new XML(result);

// Simply attach the above object to the Combobox dataprovider
cmbBox.dataProvider = xmlObj.Node;

// Above code should attach the XML tree with combo box.
// In order to display the 'name' in Combo box
cmbBox.labelField = "@name";



hey guys... I need show the field "value" of XML ... and show in a label... i cant doit:eek: i need your help...
how doit this action???
sorry, my english is bad!!!

tetito
02-25-2008, 07:02 PM
// A literal XML string, returned by Webservice (e4x format), or created within the app.
var result:String = '<XMLList>
<Node name="foo" value="100"/>
<Node name="woo" value="200"/>
</XMLList>';

// Create an XML Object
var xmlObj:XML = new XML(result);

// Simply attach the above object to the Combobox dataprovider
cmbBox.dataProvider = xmlObj.Node;

// Above code should attach the XML tree with combo box.
// In order to display the 'name' in Combo box
cmbBox.labelField = "@name";

hey i do it !!!!
i change xml...


var result:String = '<XMLList>
<Node name="foo">
<value>"100"</value>
</Node>
<Node name="woo">
<value>"200"</value>
</Node>
</XMLList>';


for select value:

ComboBox(event.target).selectedItem.@indi


:)