Dynamically Populating a DropDownList with Values from a Query

538
2
Jump to solution
04-25-2014 09:00 AM
ChrisWelch1
New Contributor
Hi all. I'm new to Flex development, so I may be missing something stupidly easy here, but I'm having an issue which I just can't find a solution for.

I'm attempting to populate a DropDownList with all of the unique values from a certain field from the result of a query. As an example, think of a feature class of buildings with a field called "BUILDING_ID". I'd like each unique value in BUILDING_ID to appear in the DropDownList.

The closest I've been able to come is using the esri:QueryTask methodology. I can get back the right number of returns, but I can't find a way to access the data. Every example of using this method seems to use a DataGrid, but I have to imagine that it's easy to pull out the data myself. The relevant parts of the code are as follows:

 private function widgetOpenedHandler(event:Event):void         {                 queryTask.execute(queryX);                 ...         }  ...  <fx:Declarations>         <esri:QueryTask id="queryTask" url="http://myserverinfo/rest/.../4" useAMF="false"/>         <esri:Query id="queryX" outfields="[BUILDING_ID]" text="%" returnGeometry="false"/> </fx:Declarations>  ...  <s:DropDownList width="200" visible="{queryTask.executeLastResult != null}"                          prompt = "Choose Building" id="dropdown2"                         dataProvider="{new ArrayCollection(queryTask.executeLastResult.attributes)}"/>


So the query runs and the DropDownList gets populated with what appears to be the correct number of features. From my understanding, the values stored in queryTask.executeLastResult.attributes are pairs of JSON keys and values. I've tried getting at these and printing them out to a TextArea for debugging purposes, but I can never get anything besides [object Object]. I've attempted things like this to no avail:

<s:TextArea text="{queryTask.executeLastResult.attributes[5].valueOf('BUILDING_ID')}"/>


So I suppose my question is really two questions. Is this the best way to populate a DropDownList and if so, how can I get to the delicious values inside queryTask.executeLastResult.attributes? If it's not the best way (or even possible), can someone point to some code?

Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Chris,

   You will need to set the labelField of the drop down list component to the field name you are intrested in, so that it knows what attribute to display in the drop down.

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus
Chris,

   You will need to set the labelField of the drop down list component to the field name you are intrested in, so that it knows what attribute to display in the drop down.
0 Kudos
ChrisWelch1
New Contributor
Thanks Robert! That does indeed work. For anyone looking at this thread in the future:


<s:DropDownList width="200" visible="{queryTask.executeLastResult != null}" 
                        prompt = "Choose Building" id="dropdown2"
                        labelField = "BUILDING_ID"
                        dataProvider="{new ArrayCollection(queryTask.executeLastResult.attributes)}"/>
0 Kudos