I'm not sure what is going on, or why. I'm sure it has something to do with the deferred results, but don't really understand. The qryTask.executeForCount is within a for loop and should execute for each key value that it finds. I am passing in a single query to execute, but it seems to execute for every key for every key. If there are 4 keys, then is executes 4 times for each key. I can't get the results until it completes running, then I'm left with 4 results, 4 times. I would assume that it would run just once each time since I'm giving it one query each time.
Please help.
for (var key in this.layerList[0].layerObject.layerDefinitions){
if (this.layerList[0].layerObject.layerDefinitions.hasOwnProperty(key)) {
var query = new Query();
query.outFields = ["*"];
var url = this.layerList[0].layerObject.url + "/" + key;
query.where = this.layerList[0].layerObject.layerDefinitions[key];
query.returnGeometry = false;
query.outSpatialReference = this.map.spatialReference;
var qryTask = new QueryTask(url);
qryTask.executeForCount(query,lang.hitch(this,function(results){
console.log(results);
}));
}
}