/*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))javascript