I am using REST API to receive some data from database. The JSON received from API if of type MAP i.e. it contains key - value pairs.
In my network tab I can see the response as
{
"items": {
"1.7.0": [{
"hostCount": 1
}],
"1.8.0": [{
"hostCount": 8
}],
"9.0": [{
"hostCount": 1
}],
"9": [{
"hostCount": 1
}],
"10": [{
"hostCount": 1
}],
"10.0": [{
"hostCount": 1
}],
"11.0": [{
"hostCount": 1
}],
"11": [{
"hostCount": 1
}],
"12": [{
"hostCount": 1
}]
},
"totalResults": 9,
"links": null
}
But when I am iterating this response in my javascript code using $.foreach loop the sequence is different.
self.RecordCollection = oj.Collection.extend({
fetchSize: (self.selectedPageSize || 20),
url: self.getQueryURL,
model: self.reportDataModel,
parse: function(response) {
$.each(response.items, function(idx, elems) {
//Some code goes here to convert key value pair to array
}
}
})
The sequence on UI after this foreach is something like this
{
"items": {
"9": [{
"hostCount": 1
}],
"10": [{
"hostCount": 8
}],
"11": [{
"hostCount": 1
}],
"12": [{
"hostCount": 1
}],
"1.7.0": [{
"hostCount": 1
}],
"1.8.0": [{
"hostCount": 1
}],
"9.0": [{
"hostCount": 1
}],
"10.0": [{
"hostCount": 1
}],
"11.0": [{
"hostCount": 1
}]
},
"totalResults": 9,
"links": null
}
I am using Oracle JET framework on UI. The sorting displayed on UI matters a lot in this case.
Please help me in understanding at which point this sorting order is getting messed up.
Edited: Also, if I try to print the response in console on UI it looks fine in expanded view (its same as returned by API). But the consolidated json shows wrong sequence and this one is taken precedence while iterating.