大佬教程收集整理的这篇文章主要介绍了Angularjs orderBy:如何从自定义排序函数调用默认比较器,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$scope.sort = function (keyName) { $scope.sortKey = keyname; $scope.reverse = !$scope.reverse; }; $scope.sortSubGrid = function (a,b) { if ($scope.sortKey === 'casenumber') { return = parseInt(b.value) -parseInt(a.value); } else { return = a.value > b.value; } };
<tr dir-paginate="agreement in agreements|orderBy:sortKey:reverse:sortSubGrid" ...>
sortSubGrid函数的后半部分用于对非数字列进行排序,但未达到我期望的结果,这只是默认比较器提供的结果.如何获取第二个子句的默认行为?
// 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; }
以上是大佬教程为你收集整理的Angularjs orderBy:如何从自定义排序函数调用默认比较器全部内容,希望文章能够帮你解决Angularjs orderBy:如何从自定义排序函数调用默认比较器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。