Create ArrayCollection from one field in a featureSet of result function

551
3
09-09-2010 10:25 AM
JamesFaron
Occasional Contributor
Basically I need to create an ArrayCollection composed of one field in a featureSet of a result function.

I complicated this task (code below) in order to help see what I was trying to get by creating a dataProvider for a list, e.g. LLdata.dataProvider = featureSet.attributes; The labelField of the list is 'Stop_ID'. The list works as expected. But, I need to create an arrayCollection composed of that field (Stop_ID) for another purpose (I don't need the list).

I'm sure that I am missing something simple. Any help or pointer will be greatly appreciated. The code that I am using may not be necessary to answer this, but I am including it if it might clarify.

function onRbeResult(featureSet:FeatureSet, token:Object = null):void        
      {
       try
       {
        for each (var gra:Graphic in featureSet.features)                    
        {   
        var obj:Object = gra.attributes;
        obj["gid"] = gid;
        gid +=1;
        }
        gridDataProvider = featureSet.attributes;
        LLdata.dataProvider = featureSet.attributes;
//        createRbeRecordData(featureSet,rbeID);//original
        var recAC:ArrayCollection = createRbeRecordData(featureSet,rbeID);
        wRepeater.dataProvider = recAC;
        var stopAC:ArrayCollection = LLdata.dataProvider as ArrayCollection;
        for each( var obj:Object in stopAC )
        {
         for each( var obj2:Object in obj )
         {
         myString += String( obj2 );
         }
        }

        Alert.show(myString);


Thanks,
Jim Faron
Tags (2)
0 Kudos
3 Replies
DanJensen
Occasional Contributor
Jim,

Not sure if this fits what you want exactly, but this is an example of how I narrow featureSet.attributes.
var newAC:ArrayCollection = new ArrayCollection;
var newObj:Object;
var i:int=0;

for (i=0; i<featureSet.attributes.length; i++)
   {
 newObj = featureSet.atttributes;
 delete newObj.Field_1;     //deletes properties of an object
 delete newObj.Field_n;
 newAC.addItem(newObj);   //add new object to new array collection  
   }
   dataGrid.dataProvider = newAC;


Good Luck,
-Dan
0 Kudos
JamesFaron
Occasional Contributor
Dan,

That was it!

Thanks so much for the help.

Jim Faron
0 Kudos
DanJensen
Occasional Contributor
Jim,

I am finding I am having some real issues using delete when transferring a subset of data to a component when I want the data to remain the same in the main application.  So I had to develop a better approach.  Here it is.
var newAC:ArrayCollection;
var newObj:Object;
var dp:ArrayCollection = featureSet.attributes;
 for each (var oldObj:Object in dp){
      newObj = new Object;
      newObj.field = oldObj.field;            newAC.addItem(newObj);
 }

Deleting the objects of the Object was also deleting the properties of objects that were used to create the new object.  This method makes sure you start with a fresh object that will not affect the old object.

Good Luck,
-Dan
0 Kudos