Select to view content in your preferred language

Sorting IdentifyResult

698
2
01-12-2011 03:35 AM
AleydisG__Pere
Regular Contributor
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
}
0 Kudos
2 Replies
derekswingley1
Deactivated User
IdentifyResult is a JavaScript object with a documented structure. Check out the docs:  Class: IdentifyResult
0 Kudos
timgogl
Deactivated User
using a tool like firebug, you can actually look at the IdentifyResult during run time.

simply place a console.log(IdentifyResult); in your javascript code, then make sure the firebug window is open before you fire your identify.

the object will show up in your firebug window, and you can browse through the various parts of your object.
0 Kudos