I see what's going on. Since selectFeatures is an asynchronous function, the loop won't stop to wait until selectFeatures is complete. It will end up with when the first selectFeatures callback is invoked, the loop already completes, and featureLayertoSelect value will be the last feature layer for all the callbacks. This is a typical trap for async programming.Change:for (k = 0; k < mapServicesList.length; k++) {
featureLayertoSelect = mapServicesList;
featureLayertoSelect.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (result) { selectFeatureCallBackFunc(featureLayertoSelect, result) }, errback);
}
To:dojo.array(mapServicesList, function(aFeatureLayer) {
aFeatureLayer.selectFeatures(query,
esri.layers.FeatureLayer.SELECTION_NEW,
function (result) { selectFeatureCallBackFunc(aFeatureLayer, result); },
errback
);
}
In the above code, aFeatureLayer is a function parameter which is local to each callback function for dojo.array, which in turn should differentiate from each other.