minor changes in sortBy
This commit is contained in:
parent
27d37ea601
commit
b28eb7ec51
1 changed files with 4 additions and 3 deletions
|
@ -487,14 +487,15 @@ Ox.range = function() {
|
||||||
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
|
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
|
||||||
@*/
|
@*/
|
||||||
Ox.sortBy = function(arr, by, fn) {
|
Ox.sortBy = function(arr, by, fn) {
|
||||||
var length = by.length, values = {};
|
var values = {};
|
||||||
|
by = Ox.toArray(by);
|
||||||
|
fn = fn || {};
|
||||||
by = by.map(function(v) {
|
by = by.map(function(v) {
|
||||||
return Ox.isString(v) ? {
|
return Ox.isString(v) ? {
|
||||||
key: v.replace(/^[\+\-]/, ''),
|
key: v.replace(/^[\+\-]/, ''),
|
||||||
operator: v[0] == '-' ? '-' : '+'
|
operator: v[0] == '-' ? '-' : '+'
|
||||||
} : v;
|
} : v;
|
||||||
});
|
});
|
||||||
fn = fn || {};
|
|
||||||
by.map(function(v) {
|
by.map(function(v) {
|
||||||
return v.key;
|
return v.key;
|
||||||
}).forEach(function(key) {
|
}).forEach(function(key) {
|
||||||
|
@ -504,7 +505,7 @@ Ox.range = function() {
|
||||||
});
|
});
|
||||||
return arr.sort(function(a, b) {
|
return arr.sort(function(a, b) {
|
||||||
var aValue, bValue, index = 0, key, ret = 0;
|
var aValue, bValue, index = 0, key, ret = 0;
|
||||||
while (ret == 0 && index < length) {
|
while (ret == 0 && index < by.length) {
|
||||||
key = by[index].key;
|
key = by[index].key;
|
||||||
aValue = values[key][a[key]];
|
aValue = values[key][a[key]];
|
||||||
bValue = values[key][b[key]];
|
bValue = values[key][b[key]];
|
||||||
|
|
Loading…
Reference in a new issue