在做玩家分数排行的时候需要对数据经常排序,这里实现得是对数组中的某个字段进行排序
// 排序
compare:function(property,desc) {
return function (a, b) {
var value1 = a[property];
var value2 = b[property];
if(desc==true){
// 升序排列
return value1 - value2;
}else{
// 降序排列
return value2 - value1;
}
}
},使用方法
this.allInfoList.sort(this.compare("wxscore",false))
console.log(this.allInfoList)
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)