DMS2

Sorting IdentifyResult

Discussion created by DMS2 on Jan 12, 2011
Latest reply on Jan 13, 2011 by lowgas
Hi all,

I'm just learning Javascript so basic things are new to me. Hope someone can clarify this to me.
I execute an identify task over several layers and get my IdentifyResult object. Then I sort my results by a certain field, but I want to sort only the results for one of the layers. I got it to work but still I'm not sure what kind of object is the IdentifyResult object.  Is it some kind of array? I mean something like this?:

IdntfResults = [[layername1, layer1attr1, layer1attr2, layer1attr3],
                     [layername1, layer1attr1, layer1attr2, layer1attr3],
                     ...
                     [layername2, layer2attr1, layer2attr2, layer2attr3, layer2attr4]
                     [layername2, layer2attr1, layer2attr2, layer2attr3, layer2attr4]
                     ...
                     [layername3, layer3attr1, layer3attr2]]


To sort the results I use this line of code:
IdntfResults.sort(compareValues);

My sort function (sort results for layer 2 by attribute 4):
function compareValues(a, b) {
var valA = a.feature.attributes["layer2attr4"];
var valB = b.feature.attributes["layer2attr4"];
return valB - valA; //descending
}

Outcomes