js sort方法根据数组中对象的某一个属性值进行排序
2021-03-20 12:27
标签:wait data function func property inf fun more === async getList() { // 排序比较 js sort方法根据数组中对象的某一个属性值进行排序 标签:wait data function func property inf fun more === 原文地址:https://www.cnblogs.com/2Octobering/p/13920360.html
await indexmodel.findAllSeller(this.queryInfo, data => {
console.log(data);
if (data.length this.loadingType = ‘noMore‘;
}
if (this.queryInfo.pageNo === 1) {
this.list = data;
this.list.sort(this.compare(‘distance‘))
} else {
this.list = this.list.concat(data);
this.list.sort(this.compare(‘distance‘))
}
});
},
compare(property){
return function(a,b){
let value1 = a[property];
let value2 = b[property];
return value1 - value2;
}
},
console.log(this.list.sort(this.compare(‘distance‘)))
文章标题:js sort方法根据数组中对象的某一个属性值进行排序
文章链接:http://soscw.com/index.php/essay/66705.html