Select to view content in your preferred language

How to store multiple featureLayer.queryFeatures results in an array or object

977
1
Jump to solution
09-04-2014 09:46 AM
TracySchloss
Honored Contributor

I have a queryFeatures on a featureLayer that is based on mutiple objectIds. I need to iterate through each feature and store attributes in an array.  I need to keep each feature's array in another array (or maybe an object?) so I can have it as input to my chart.

gQuery = new Query();

  gQuery.objectIds = idList;  //defined earlier

seriesList.length = 0;  //declared earlier as seriesList = [];

featureLayer.queryFeatures(gQuery, function(results) {

    arrayUtils.forEach(results.features, function (result){

      var list = createRateList(result);

console.log("list is " + list);

          seriesList.push({data: list});

});

});

function createRateList(results){

  var atts = results.attributes;

  var county = atts.County;

  rateList.length = 0;

  reverseRateFields.length = 0;

  //gets the rate values for selected county for all years, list of field defined earlier

      arrayUtils.forEach(reverseRateFields, function (field){

         rateList.push(atts[field]);

      });  

    return rateList;

}

At the point I have do a console.log on list, it contains the values I expect.  I add it to my seriesList and it still looked OK.   Going to the next feature, I the console.log display what I expect from the list, but what I push to seriesList affects what's already in there.  Examining the contents of seriesList shows the initial item [0] with content I just added from the 2nd time through.  This continues through how ever many features I had from queryFeatures until I have a seriesList full of the exact same list of values, which are from the final feature.

I don't know if I have a looping problem, or don't understand the nature of array variables.

0 Kudos
1 Solution

Accepted Solutions
TracySchloss
Honored Contributor

It seems to work if I make a new array by using splice and push that to my 'array of arrays' instead. 

View solution in original post

0 Kudos
1 Reply
TracySchloss
Honored Contributor

It seems to work if I make a new array by using splice and push that to my 'array of arrays' instead. 

0 Kudos