how to query with combobox with Flex

772
3
09-28-2010 07:34 PM
SpencerTrevor
New Contributor
Hi there,

Is there any sample that I can refer to make a Query using Combobox in Flex? I am very new in Flex so any help will do.

Thank you in advance
Tags (2)
0 Kudos
3 Replies
Alexandervan_der_Schans
New Contributor
I am very much looking to do the same thing so I will keep a close eye on this thread too!
0 Kudos
erictruchon
New Contributor
Code exemple (multi combobox)

There exist many ways to populate combobox, search in flex documentation

<mx:ComboBox id="rue" width="90%" prompt="Sélectionner une rue ..." dataProvider="{XMLData}" labelField="name" />
       
<mx:ComboBox id="civique" width="90%" prompt="Sélectionner un numéro civique ..." dataProvider="{rue.selectedItem.civique}"/>
      
<mx:HBox horizontalAlign="center" width="100%">
<mx:Button label="{submitLabel}" click="queryFeaturesText(4)"/>
<mx:Button label="{clearLabel}" click="clear()"/>
</mx:HBox>

i hope this help
0 Kudos
DanJensen
Occasional Contributor
Spencer and Alexander,

There are, of course, two stages. 

  1. Populate the combobox with items from a layer during application intialization.

  2. Use the user selected item to query agains that layer

One problem with step one that I had was that the items in the layer were not unique, but I needed to provide a unique list for the user.  First I did a query to return all records in the layer.  Then I filtered that returned dataset for unique values of the field I wanted to use to populate the control.  The code below shows how I filtered the data.  I actually used a drop down list control, but the process is the same.
private function onDDLInitComplete(fSet:FeatureSet, token:Object=null):void
   {
    //defines and sorts a unique list of values for the drop down list control
    //Populates the bindable application variable ddlValuesAC
    var i:int = 1;
    var item:String;
    var sortAttr:Array=fSet.attributes.sortOn("FieldName");
    for (var j:int=0; j<fSet.attributes.length-1; j++)
    {
     item = sortAttr.FieldName;
     //getItemIndex returns -1 it item is not found in the array
     i=ddlValuesAC.getItemIndex(item);
     if (i==-1){
      ddlValuesAC.addItem(item);
     }
    }
   }


Now that I have a drop down list with just the unique values from the layer, I can return one to many records depending on the user's selection.  Code example below.

protected function ddlControl_changeHandler(event:IndexChangeEvent):void
   {
    mapQuery.where="fieldName = '" + ddlControl.selectedItem + "'";
    mapQuery.geometry = null;  //this in case geometry was used in previous query
    mapQueryTask.execute(mapQuery, new AsyncResponder(onQueryExecuteComplete, onFault));
   }

You will use the onQueryExecuteCompleteFunction to display the data to the user in the manner that meets your application requirements.  Likely you will use the results to populate a variable that is bound to the dataProvider attribute of a dataGrid control.

Good Luck,
-Dan
0 Kudos