function MyController($scope) {
var singleSort = [
{ "text": "Second", "a": 2 },
{ "text": "Fifth", "a": 5 },
{ "text": "First", "a": 1 },
{ "text": "Fourth", "a": 4 },
{ "text": "Third", "a": 3 }
];
var multipleSort = [
{ "text": "Second", "a": 1, "b": 2 },
{ "text": "Fifth", "a": 2, "b": 2 },
{ "text": "First", "a": 1, "b": 1 },
{ "text": "Fourth", "a": 2, "b": 1 },
{ "text": "Third", "a": 1, "b": 3 }
];
var singleSortIterator = function(item) {
return item.a;
};
var multipleSortIterator = function(item) {
return [item.a, item.b];
};
var singleSortReversedIterator = function(item) {
return -item.a;
};
var multipleSortReversedIterator = function(item) {
return -[item.a, item.b];
};
$scope.singleSort = _.sortBy(singleSort, singleSortIterator);
$scope.multipleSort = _.sortBy(multipleSort, multipleSortIterator);
$scope.singleSortReversed = _.sortBy(singleSort, singleSortReversedIterator);
$scope.multipleSortReversed = _.sortBy(multipleSort, multipleSortReversedIterator);
}
。
並べ替えアルゴリズムは、multipleSortReversedとは別にすべて機能しています。ここに明らかな問題はありますか?
http://jsfiddle.net/andybooth/QEBUx/
私が得ている結果は
Single sort
First
Second
Third
Fourth
Fifth
Multiple sort
First
Second
Third
Fourth
Fifth
Single sort (reversed)
Fifth
Fourth
Third
Second
First
Multiple sort (reversed)
Second
Fifth
First
Fourth
Third