Select to view content in your preferred language

Populate Combobox from FeatureSet

1792
14
10-12-2010 07:46 AM
DonCaviness
Occasional Contributor
I have a combobox that I want to populate with a field that is being returned in a featureSet from a query.  I am querying a table and getting the results but I am having trouble figuring out what I am missing to populate the combobox.  Here is the code I am using.  Can anyone see what I am doing wrong?

for each (var graphic:Graphic in featureSet.features)
{
 var category:String = graphic.attributes.category;
 var subcat:String = graphic.attributes.subCategory;
       
 var data:Object = {
  category: category,
  subcat: subcat
 }
 cboCategory.dataProvider = data.subcat;
}
Tags (2)
0 Kudos
14 Replies
RobertScheitlin__GISP
MVP Emeritus
Nadeem,

   You should post your code, as it is not very clear where you are going wrong.
0 Kudos
NadeemShaukat
Deactivated User
Robert,

Here is the code. I declared 2nd variable for 2nd field in the same function which is returning "object Object". I guess the problem is at "for each" loop.

Nadeem

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768"
    xmlns:esri="http://www.esri.com/2008/ags" xmlns:mx2="library://ns.adobe.com/flex/mx"
    creationComplete="creationCompleteHandler(event)">
<fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.QueryEvent;
  
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.FlexEvent;
  
  
   protected function creationCompleteHandler(event:FlexEvent):void
   {
    queryData();
   }
  
   private function queryData():void
   {
    queryTask.execute(query);
    queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onQueryComplete);
   }
  
   private function onQueryComplete(event:QueryEvent):void
   {
    var featureSet:FeatureSet = event.featureSet;
    var results:ArrayCollection = new ArrayCollection();
   
    for each (var graphic:Graphic in featureSet.features)
    {
     var fieldValue1:String = graphic.attributes["STATE_NAME"].toString();
     results.addItem({label1: fieldValue1, data:graphic});
    
     var fieldValue2:String = graphic.attributes["POP2000"].toString();
     results.addItem({label2: fieldValue2, data:graphic});
    }
    cmb1.labelField = "label1";
    cmb1.dataProvider = results;
   
    cmb2.labelField = "label2";
    cmb2.dataProvider = results;
   }
    
  ]]>
</fx:Script>

<fx:Declarations>
<esri:QueryTask
  id="queryTask"
  useAMF="false"
  url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
<esri:Query
  id="query"
  returnGeometry="false"
  where="1=1"
  outFields='["STATE_NAME","POP2000"]'/>
</fx:Declarations>
<s:ComboBox id="cmb1" x="179" y="205" labelField=""/>
<s:ComboBox id="cmb2" x="479" y="205" labelField=""/>

</s:Application>
0 Kudos
NadeemShaukat
Deactivated User
Robert,

Here is the code. I declared 2nd variable for 2nd field in the same function which is returning "object Object". I guess the problem is at "for each" loop.

Nadeem

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" 
    xmlns:esri="http://www.esri.com/2008/ags" xmlns:mx2="library://ns.adobe.com/flex/mx"
    creationComplete="creationCompleteHandler(event)">
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.QueryEvent;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   
   
   protected function creationCompleteHandler(event:FlexEvent):void
   {
    queryData();
   }
   
   private function queryData():void
   {
    queryTask.execute(query);
    queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onQueryComplete);
   }
   
   private function onQueryComplete(event:QueryEvent):void
   {
    var featureSet:FeatureSet = event.featureSet;
    var results:ArrayCollection = new ArrayCollection();
    
    for each (var graphic:Graphic in featureSet.features)
    {
     var fieldValue1:String = graphic.attributes["STATE_NAME"].toString(); 
     results.addItem({label1: fieldValue1, data:graphic});
     
     var fieldValue2:String = graphic.attributes["POP2000"].toString(); 
     results.addItem({label2: fieldValue2, data:graphic});
    }
    cmb1.labelField = "label1";
    cmb1.dataProvider = results;
    
    cmb2.labelField = "label2";
    cmb2.dataProvider = results;
   }
     
  ]]>
 </fx:Script>
 
 <fx:Declarations>
 <esri:QueryTask
  id="queryTask"
  useAMF="false"
  url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
 <esri:Query
  id="query"
  returnGeometry="false"
  where="1=1"
  outFields='["STATE_NAME","POP2000"]'/>
 </fx:Declarations>
 <s:ComboBox id="cmb1" x="179" y="205" labelField=""/>
 <s:ComboBox id="cmb2" x="479" y="205" labelField=""/>
 
 
 
</s:Application>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Nadeem,

   Very simple. Don't try to use the same array collection for both comboboxes.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/halo" 
      minWidth="1024" minHeight="768" 
      xmlns:esri="http://www.esri.com/2008/ags"
      xmlns:mx2="library://ns.adobe.com/flex/mx"
      creationComplete="creationCompleteHandler(event)">
 <fx:Script>
  <![CDATA[
   import com.esri.ags.FeatureSet;
   import com.esri.ags.Graphic;
   import com.esri.ags.events.QueryEvent;
   
   import mx.collections.ArrayCollection;
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   
   
   protected function creationCompleteHandler(event:FlexEvent):void
   {
    queryData();
   }
   
   private function queryData():void
   {
    queryTask.execute(query);
    queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onQueryComplete);
   }
   
   private function onQueryComplete(event:QueryEvent):void
   {
    var featureSet:FeatureSet = event.featureSet;
    var results:ArrayCollection = new ArrayCollection();
    var results2:ArrayCollection = new ArrayCollection();
    
    for each (var graphic:Graphic in featureSet.features)
    {
     var fieldValue1:String = graphic.attributes["STATE_NAME"].toString(); 
     results.addItem({label1: fieldValue1, data:graphic});
     
     var fieldValue2:String = graphic.attributes["POP2000"].toString(); 
     results2.addItem({label2: fieldValue2, data:graphic});
    }
    cmb1.labelField = "label1";
    cmb1.dataProvider = results;
    
    cmb2.labelField = "label2";
    cmb2.dataProvider = results2;
   }
   
  ]]>
 </fx:Script>
 
 <fx:Declarations>
  <esri:QueryTask
   id="queryTask"
   useAMF="false"
   url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
  <esri:Query
   id="query"
   returnGeometry="false"
   where="1=1"
   outFields='["STATE_NAME","POP2000"]'/>
 </fx:Declarations>
 <s:ComboBox id="cmb1" x="179" y="205" labelField=""/>
 <s:ComboBox id="cmb2" x="479" y="205" labelField=""/>
</s:Application>
0 Kudos
NadeemShaukat
Deactivated User
Thanks muck Robert.

I would have not figured it out myself.

Nadeem
0 Kudos