list.sortArr = function(arr,value,type){
if("Asc" == type){
arr.sort(list.byAsc(value));
}else if("Desc" == type){
arr.sort(list.byDesc(value));
}
}
/* 对象数组排序
* 排序,name:排序字段。 */
// 升序
list.byAsc = function(name){
return function(o, p){
var a, b;
if (typeof o === "object" && typeof p === "object" && o && p) {
a = o[name];
b = p[name];
if (a === b) {
return 0;
}
if (typeof a === typeof b) {
return a < b ? -1 : 1;
}
return typeof a < typeof b ? -1 : 1;
}
else {
throw ("error");
}
}
}
// 降序
list.byDesc = function(name){
return function(o, p){
var a, b;
if (typeof o === "object" && typeof p === "object" && o && p) {
a = o[name];
b = p[name];
if (a === b) {
return 0;
}
if (typeof a === typeof b) {
return a > b ? -1 : 1;
}
return typeof a > typeof b ? -1 : 1;
}
else {
throw ("error");
}
}
}