无序的JSONArray在页面重新排序
1.JAVA后取得一个LIST,并转换成JSONArray.
JSONArray ja= new JSONArray(); for(Iterator<Info> it = list.iterator();it.hasNext();){ JSONObject jso = new JSONObject(); Info info = (Info)it.next(); jso.put("aa",info.getAa()); jso.put("bb", info.getBb()); jso.put("cc",info.getCc()); } response.getWriter().write(ja.toString());
2.通过AJAX取回JA并排序,这里是降序,要升序的话,去掉reverse()即可。
$.ajax({ async : false, type : "get", url : "/action.do?method=abc", contentType:"application/x-www-form-urlencoded; charset=utf-8", dataType : 'json', data:'', success : function(ja) { if(ja.length >0){ dosomething... }else{ dosomething... } //排序 var obj =ja; obj.sort(function(a,b){ return a.a - b.a; }).reverse(); } });
相关推荐
adonislu 2020-02-14
somebodyoneday 2020-06-15
adonislu 2020-06-02
baijinswpu 2020-02-19
83163452 2020-01-28
adonislu 2020-01-10
baijinswpu 2020-01-01
adonislu 2019-12-31
baijinswpu 2019-12-28
xufankang 2019-12-19
somebodyoneday 2019-12-07
abcx 2015-05-25
somebodyoneday 2019-10-30
newthon 2019-10-21
ZCMUCZX 2016-04-14
iovaaron 2015-04-10
Dolphinsz 2016-04-25