排序函数,json:排序对象,base:按照json中哪个字段排序,turn:正序、倒序*/
function sort(json,base,turn){
json.sort(function(n,m){
var s= n[base];
var e= m[base];
if(typeof(s)=='string'&&typeof(e)=='string'){
if(turn=='z'){
return s.localeCompare(e);
}else if(turn=='d'){
return e.localeCompare(s);
}
}else if(typeof(s)=='number'&&typeof(e)=='number'){
if(turn=='z'){
return s-e;
}else if(turn=='d'){
return e-s;
}
}
})
return json;
}

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-02-15
  • 2021-09-17
  • 2022-02-24
猜你喜欢
  • 2021-07-30
  • 2021-10-13
  • 2022-12-23
  • 2021-11-09
  • 2021-08-05
  • 2022-03-10
  • 2021-07-08
相关资源
相似解决方案