function jsonSortByValue(x, y){ //jsonKey是你要排序的json的键 var a = x.jsonKey, b = y.jsonKey; // 如果是按照字符长度降序排序,则应该为bStr.length - aStr.length return a - b;}//jsonData 是你获取的json数组数据,调用了sort()方法以后,jsonData就已经是排序好的数据了jsonData.sort(jsonSortByValue);
本文共 300 字,大约阅读时间需要 1 分钟。
function jsonSortByValue(x, y){ //jsonKey是你要排序的json的键 var a = x.jsonKey, b = y.jsonKey; // 如果是按照字符长度降序排序,则应该为bStr.length - aStr.length return a - b;}//jsonData 是你获取的json数组数据,调用了sort()方法以后,jsonData就已经是排序好的数据了jsonData.sort(jsonSortByValue);
转载于:https://my.oschina.net/chendongj/blog/1845731