function compare(propertyName, index) {
return function(a, b) {
let value1 = a[propertyName];
let value2 = b[propertyName];
if (vm.reverse[index]) {
return value2 - value1;
} else {
return value1 - value2;
}
};
}
propertyName为对象里面的建的名字
arr.sort(compare('age')) 得到的就是数组里面对象排序的结果
(案例:能源管理项目)key_equipmemt.controller.js文件,大概位置在535行