This simple task is really very confusing :-(

I have been through tutorials, references with comboboxes and Arrays and
this really appears very simple there. However when it comes to remoteobject
it gets extremenly complicated :-(

My guess is.. is there any easy way to convert my ArrayCollection that comes
from the RemoteObject into an array which has no problems at all with the
combobox?

i.e. in order to use this dataprovider in a combobox is very easy!

[Bindable]
            public var cards: Array = [ {label:"Visa", data:1},
                {label:"MasterCard", data:2}, {label:"American Express",
data:3} ];

            [Bindable]
            public var selectedItem:Object;

Can I get a remoteobject return me some date and using some simple AS3 to
convert what comes back from my service into this?

thanks,
George

ps: sorry if this sounds like a dump idea - i m not really experianced Flex
Developer at all, just started it :-)



On 10/15/07, Randy Martin <[EMAIL PROTECTED]> wrote:
>
>    Here's the code for the Adobe BindableComboBox.mxml that's generated by
> the ColdFusion Application Wizard. This will do what you want.
>
> <?xml version="1.0" encoding="utf-8"?>
> <!--
>
> ////////////////////////////////////////////////////////////////////////////////
> //
> //  Copyright (C) 2003-2006 Adobe Macromedia Software LLC and its
> licensors.
> //  All Rights Reserved. The following is Source Code and is subject to
> all
> //  restrictions on such code as contained in the End User License
> Agreement
> //  accompanying this product. If you have received this file from a
> source
> //  other than Adobe, then your use, modification, or distribution of this
> file
> //  requires the prior written permission of Adobe.
> //
> //  @author Dean Harmon
> //  @author Mike Nimer
>
> ////////////////////////////////////////////////////////////////////////////////
> -->
> <mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml"; xmlns="*"
> creationComplete="componentInit()">
>   <mx:Script>
>     <![CDATA[
>       import mx.utils.ObjectUtil;
>       import mx.controls.Alert;
>
>       [Bindable]
>       public var valueField:String = "";
>
>       [Bindable]
>       public var labelFields:Array = [];
>
>       public function componentInit():void {
>         this.labelFunction = renderLabelFunction;
>       }
>
>       public function renderLabelFunction(item:Object):String {
>         var result:String = "";
>         if (labelFields.length == 0) {
>           if (labelField != null) {
>             return item[labelField];
>           }
>           else {
>             return item.toString();
>           }
>         }
>         else {
>           for(var i:int=0; i < labelFields.length; i++) {
>             if (i > 0) {
>               result += " ";
>             }
>
>             result += item[labelFields[i]];
>           }
>         }
>         return result;
>       }
>
>       override public function set selectedItem(val:Object):void {
>         //Alert.show(valueField +":" +ObjectUtil.toString(val));
>         if (this.valueField != null) {
>           for(var i:int=0; i < this.dataProvider.source.length; i++) {
>             var item:Object = this.dataProvider.source[i];
>
>             if (item[valueField] == val) {
>               // if it matches, make it selected.
>               this.selectedIndex = i;
>               break;
>             }
>           }
>         }
>         else {
>           super.selectedItem(val);
>         }
>       }
>
>       public function get selectedItemValue():Object {
>         if (this.valueField != null && selectedItem != null) {
>           return selectedItem[valueField];
>         }
>         else {
>           return text;
>         }
>       }
>     ]]>
>   </mx:Script>
> </mx:ComboBox>
>
> ~randy
>
>
> --- In flexcoders@yahoogroups.com, "T" <[EMAIL PROTECTED]> wrote:
> >
> > Actually this is a good question, and I am in the same boat and also do
> > not know the correct way to handle this.
> >
> > I have a value object in my data model that came from a table in a
> > database via a RemoteObject call. The VO has an int field that is a
> > foreign key reference to a record in the people table. I have a
> > combobox that gets its list of people from the people table, including
> > their person_id fields, displays the name field, but I need to bind the
> > combo item to the person_id int field in the VO. This does not seem to
> > be possible out of the box, and it looks like flex3 doesn't have it
> > either. Does this mean I have to manually implement an itemchanged
> > event handler for changes in the combo box, and manually set the
> > selected combo item when the value object is first loaded? And even
> > with this, if the model changes, the view would not see it happen. Is
> > there some way to make this binding?
> >
> > T
> >
> > --- In flexcoders@yahoogroups.com, "George Georgiou" george1977@
> > wrote:
> > >
> > > Hi there,
> > >
> > > I got a remoteobject which loads data from an sql table. I got
> > something
> > > like 5 fields for customers.
> > >
> > > I want to populate a combobox showing the name of the customer and
> > having
> > > as a value the customer_id.
> > >
> > > After Googling it a bit, I have ended up with this:
> > >
> > > <mx:ComboBox id="customer_name" dataProvider="{customerData}"
> > > labelField="customer_name"/>
> > >
> > > this works great! But what about the dataField? (at my suprise I have
> > found
> > > out that although a labelField does exist - which is cool, a dataField
> > > attribute does not exist).
> > >
> > > How can I bind the customer_id into my combobox? Any ideas?
> > >
> > > thanks,
> > > George
> > >
> >
>
> 
>

Reply via email to