Hmm, hadn't thought about it in that light. But it seems you are
correct, I am sorting an array of JSON objects
Alright so I tried my hand at this, and to be honest it is a little over
my head. I found a JavaScript function that I could use to sort the
values in the Array. It looks like this:
var sort_by = function(field, reverse, primer){
var key = function (x) {return primer ? primer(x[field]) :
x[field]};
return function (a,b) {
var A = key(a), B = key(b);
return ((A < B) ? -1 : (A > B) ? +1 : 0) *
[-1,1][+!!reverse];
}
};
And the suggested usage would be something like this:
// Provided example: Sort by city, case-insensitive, A-Z
homes.sort(sort_by('city', false, function(a){return a.toUpperCase()}));
The following is what I basically put together. Unfortunately I have no
clue what the primer is supposed to do so I went with the previous
example since it didn't matter if the main_ID was lower or upper case.
Alas it isn't working and I am not sure what is wrong or where to go
from here.
results = results.sort(sort_by('MAIN_ID',false,function(a){return
a.toUpperCase()}));
Any thoughts?
________________________________
If you reply to this email, your message will be added to the discussion
below:
http://osgeo-org.1560.n6.nabble.com/How-to-sort-a-selection-set-tp434438
3p4350951.html
To unsubscribe from How to sort a selection set, click here
<http://osgeo-org.1560.n6.nabble.com/template/NamlServlet.jtp?macro=unsu
bscribe_by_code&node=4344383&code=c291ZGVtYW5zQHJ1ZWtlcnQtbWllbGtlLmNvbX
w0MzQ0MzgzfC0xMzkyMzk3NTUy> .
NAML
<http://osgeo-org.1560.n6.nabble.com/template/NamlServlet.jtp?macro=macr
o_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespac
es.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.w
eb.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Ae
mail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabb
le%3Aemail.naml>
--
View this message in context:
http://osgeo-org.1560.n6.nabble.com/How-to-sort-a-selection-set-tp4344383p4352080.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
_______________________________________________
mapguide-users mailing list
mapguide-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users