在二次开发的过程里,发现有段老代码是走后台的,在后台进行双重排序的是用Comparator进行的,
他为了这个操作,再次请求了后台,太浪费开销,于是我它挪到前台。
js + sort()
例子:
var peopleArray = [
{age:18, wage:7000},
{age:19, wage:8000},
{age:19, wage:7000},
{age:26, wage:100000},
{age:38, wage:28000},
{age:19, wage:9000}
];
peopleArray.sort(function(a,b){
if (a.wage === b.wage) {
return b.age - a.age;
}
return b.wage - a.wage ;
});
$.each(peopleArray, function(index, people) {
console.info("age:" + people.age + "--->wage:" + people.wage);
});
before:
after: