Angularjs orderBy:如何从自定义排序函数调用默认比较器

Angularjs orderBy:如何从自定义排序函数调用默认比较器,angularjs,sql-order-by,comparator,Angularjs,Sql Order By,Comparator,我有一个自定义排序函数,可以将网格中一列的字符串转换为数字。其他列由字符串或日期值组成。我有一个自定义排序函数,用于检查数字列并执行转换,但对于其他值,我需要默认比较器的行为。我如何做到这一点 $scope.sort=函数(键名){ $scope.sortKey=keyname; $scope.reverse=!$scope.reverse; }; $scope.sortSubGrid=函数(a,b){ 如果($scope.sortKey==='caseNumber'){ return=par

我有一个自定义排序函数,可以将网格中一列的字符串转换为数字。其他列由字符串或日期值组成。我有一个自定义排序函数,用于检查数字列并执行转换,但对于其他值,我需要默认比较器的行为。我如何做到这一点

$scope.sort=函数(键名){
$scope.sortKey=keyname;
$scope.reverse=!$scope.reverse;
};
$scope.sortSubGrid=函数(a,b){
如果($scope.sortKey==='caseNumber'){
return=parseInt(b.value)-parseInt(a.value);
}
否则{
返回=a.值>b.值;
}
};
根据中的代码,您可以使用默认值或自定义值,但正如您所描述的,这将是一个很好的功能

// Define the `compare()` function. Use a default comparator if none is specified.
var compare = isFunction(compareFn) ? compareFn : defaultCompare;
因此,您始终可以获取原始的defaultCompare代码并对其进行修改

// source orderBy.js
function defaultCompare(v1, v2) {
  var result = 0;
  var type1 = v1.type;
  var type2 = v2.type;

  if (type1 === type2) {
    var value1 = v1.value;
    var value2 = v2.value;

    if (type1 === 'string') {
      // Compare strings case-insensitively
      value1 = value1.toLowerCase();
      value2 = value2.toLowerCase();
    } else if (type1 === 'object') {
      // For basic objects, use the position of the object
      // in the collection instead of the value
      if (isObject(value1)) value1 = v1.index;
      if (isObject(value2)) value2 = v2.index;
    }

    if (value1 !== value2) {
      result = value1 < value2 ? -1 : 1;
    }
  } else {
    result = type1 < type2 ? -1 : 1;
  }

  return result;
}
//source orderBy.js
函数defaultCompare(v1、v2){
var结果=0;
var type1=v1.type;
var type2=v2.type;
如果(类型1==类型2){
var value1=v1.0的价值;
var value2=v2.0;
如果(类型1=='string'){
//不区分大小写比较字符串
value1=value1.toLowerCase();
value2=value2.toLowerCase();
}else if(type1==='object'){
//对于基本对象,使用对象的位置
//在集合中,而不是在值中
如果(isObject(value1))value1=v1.index;
如果(isObject(value2))value2=v2.index;
}
如果(值1!==值2){
结果=值1<值2?-1:1;
}
}否则{
结果=类型1<类型2?-1:1;
}
返回结果;
}