Skip to content
Browse files

Fixes SC.ArrayController's Array orderBy to work for more than a sing…

…le Array item.

- It was replacing the object with the value, so subsequent iterations would fail to find the key on the object (now a value).
  • Loading branch information...
1 parent ab8211d commit d61c747c14b4789cb5e34a242f64e3efc1b88e0e @publickeating publickeating committed Jun 15, 2012
Showing with 5 additions and 5 deletions.
  1. +5 −5 frameworks/core_foundation/controllers/array.js
View
10 frameworks/core_foundation/controllers/array.js
@@ -379,7 +379,7 @@ SC.ArrayController = SC.Controller.extend(SC.Array, SC.SelectionSupport,
// generate comparison function if needed - use orderBy
func = func || function(a,b) {
- var status, key, match, descending;
+ var status, key, match, valueA, valueB;
for(var i=0, l=orderBy.get('length'); i<l && !status; i++) {
key = orderBy.objectAt(i);
@@ -388,18 +388,18 @@ SC.ArrayController = SC.Controller.extend(SC.Array, SC.SelectionSupport,
//@if(debug)
SC.warn("SC.ArrayController's orderBy direction syntax has been changed to match that of SC.Query and MySQL. Please change your String to 'key DESC' or 'key ASC'. Having 'ASC' or 'DESC' precede the key has been deprecated.");
//@endif
- match = key.match(/^(ASC )?(DESC )?(.*)$/);
+ match = key.match(/^(ASC )?(DESC )?(.*)$/);
key = match[3];
} else {
match = key.match(/^(\S*)\s*(DESC)?(?:ASC)?$/);
key = match[1];
}
order = match[2] ? -1 : 1;
- if (a) { a = a.isObservable ? a.get(key) : a[key]; }
- if (b) { b = b.isObservable ? b.get(key) : b[key]; }
+ if (a) { valueA = a.isObservable ? a.get(key) : a[key]; }
+ if (b) { valueB = b.isObservable ? b.get(key) : b[key]; }
- status = SC.compare(a, b) * order;
+ status = SC.compare(valueA, valueB) * order;
}
return status ;

0 comments on commit d61c747

Please sign in to comment.
Something went wrong with that request. Please try again.