|
|
|
@ -84,16 +84,17 @@ Cursor.prototype._exec = function(callback) { |
|
|
|
|
if (this._sort) { |
|
|
|
|
keys = Object.keys(this._sort); |
|
|
|
|
|
|
|
|
|
// Going backwards so that the first sort is the last that gets applied
|
|
|
|
|
// Sorting
|
|
|
|
|
var criteria = []; |
|
|
|
|
for (i = 0; i < keys.length; i++) { |
|
|
|
|
key = keys[i]; |
|
|
|
|
criteria.push({ key: key, direction: self._sort[key] }); |
|
|
|
|
} |
|
|
|
|
res.sort(function(a, b) { |
|
|
|
|
for (var i = 0; i < criteria.length; i++) { |
|
|
|
|
var criterion = criteria[i]; |
|
|
|
|
var compare = criterion.direction * model.compareThings(model.getDotValue(a, criterion.key), model.getDotValue(b, criterion.key)); |
|
|
|
|
var criterion, compare, i; |
|
|
|
|
for (i = 0; i < criteria.length; i++) { |
|
|
|
|
criterion = criteria[i]; |
|
|
|
|
compare = criterion.direction * model.compareThings(model.getDotValue(a, criterion.key), model.getDotValue(b, criterion.key)); |
|
|
|
|
if (compare !== 0) { |
|
|
|
|
return compare; |
|
|
|
|
} |
|
|
|
|