Select to view content in your preferred language

Repeater CurrentItem Value and Where Clause

1284
4
10-13-2010 03:56 PM
KomanDiabate
Deactivated User
Hello All,
I am trying to figure it out how setup the where clause on my query by pulling the value from the wRepeater on the Flex Sample Viewer. However, I am unable to correclty read the value to the query where clause. I also tried to store the value to a simple mx:label and I am still having problems.
Can someone please help me figure this out, or tell me if this is even possible.
Thanks.

<esri:QueryTask id="existingQueryTask" showBusyCursor="true"
            url="http://ArcGIS/rest/services/Test/BaseLayers/MapServer/3" />         
         <esri:Query id="exParkQuery" where="ParkId='{wRepeater.currentItem.ParkId}'" returnGeometry="true">
            <esri:outFields>*</esri:outFields>
        </esri:Query>
Tags (2)
0 Kudos
4 Replies
Drew
by
Frequent Contributor
Here is a sample that shows how to get the item.

Take a look at the code "doQuery(event...)" and see how to get the repeater index then get that item from your array.



<?xml version="1.0" encoding="utf-8"?>

<s:Application name="Repeater Test"
      xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:esri="http://www.esri.com/2008/ags">
 
 <fx:Script>
  <![CDATA[
   import com.esri.ags.events.QueryEvent;
   import mx.controls.Alert;
   import mx.states.State;
   
   private function doQuery(event:Event):void
   {
    var state:String = arrList.getItemAt(event.currentTarget.repeaterIndex).toString();
    var where:String = "STATE_NAME = '"+state+"'";
    query.where = where;
    query.outFields = ["STATE_NAME"];
    queryTask.addEventListener(QueryEvent.EXECUTE_COMPLETE, onQueryComplete);
    queryTask.execute(query);    
   }
   
   private function onQueryComplete(result:QueryEvent):void
   {
    //Alert.show("done"); 
   }

  ]]>
 </fx:Script>
 
 
 <fx:Declarations>
  <s:ArrayList id="arrList" source="[New York,California,Florida]"/>
  <esri:QueryTask useAMF="false" id="queryTask" showBusyCursor="true" url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"/>
  <esri:Query id="query" outSpatialReference="{myMap.spatialReference}" returnGeometry="true"/>
 </fx:Declarations>
 
 
 <esri:Map id="myMap">
  <esri:extent>
   <esri:Extent xmin="-14298000" ymin="2748000" xmax="-6815000" ymax="7117000">
    <esri:SpatialReference wkid="102100"/>
   </esri:Extent>
  </esri:extent>
  <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Physical_Map/MapServer"/>
  <esri:GraphicsLayer id="myGraphicsLayer" graphicProvider="{queryTask.executeLastResult.features}"/>
 </esri:Map>

 
 <s:VGroup horizontalCenter="0" verticalCenter="0">
  <mx:HBox>
   <mx:Repeater id="rpt" dataProvider="{arrList}">
    <s:Button click="doQuery(event)" left="20" top="335" label="{rpt.currentItem}" />
   </mx:Repeater>
  </mx:HBox>
 </s:VGroup>
 
 
</s:Application>



Drew
0 Kudos
KomanDiabate
Deactivated User
Drew,
Thank you so much for your reply. From your code, I understand you are storing the value in a string and then assigning it in the where clause. But I am having hard time applying this to the SFV.
In my application, I am already querying a set of data and displaying it in the widget. So I want to get the value (ID) of the data that I click on and store this in the label1.text (Please see attachment). Still not sure how to do this. Hope you can put me in the right direction.
Thanks.
0 Kudos
Drew
by
Frequent Contributor
Can you post your repeater code?
0 Kudos
KomanDiabate
Deactivated User
Sure, Here are the major parts.

1 -So the first query is just a regular SFV SearchWidget Query.

2- Second function tries to assign repeater id to label (unsuccessfully):
private function rep(event:MouseEvent):void
{          
     t.text='{wRepeater.currentItem.ParkId}';
}

3- The third part is the query itself in actionscript where the where clause in located.
I noticed if I formulate the where clause like this everything will  work:
Where="ParkId=2" but I wont to get the id on the clicked repeater.

<esri:QueryTask id="existingQueryTask"
         showBusyCursor="true"
            url="http://*****/ArcGIS/rest/services/Test/BaseLayers/MapServer/3" />        
         <esri:Query id="exParkQuery" where="ParkId='{wRepeater.currentItem.ParkId}'" returnGeometry="true">
            <esri:outFields>*</esri:outFields>
        </esri:Query>

4 - Here is the repeater that call the first function on mouseup event.
<mx:Label id="t"/>
<mx:Repeater id="wRepeater">
<widgets:RecordData infoData="{wRepeater.currentItem}"      mouseOver="mouseOverRecord(event)" mouseOut="mouseOutRecord()" click="clickRecord(event)" mouseUp="rep(event)"/>
</mx:Repeater>

Thanks.
0 Kudos