javascrpit sort()数组对象中排序
/*ionic 调用
* @param attr 排序的属性 如number属性
* @param rev true表示升序排列,false降序排序
* */
commonSortMethod(attr,rev){
//第二个参数没有传递 默认升序排列
if(rev == undefined){
rev = 1;
}else{
rev = (rev) ? 1 : -1;
}
return function(a,b){
a = a[attr];
b = b[attr];
if(a < b){
return rev * -1;
}
if(a > b){
return rev * 1;
}
return 0;
}
}
arrt.sort(this.commonSortMethod(atrr,false))

浙公网安备 33010602011771号