ajax 如何返回list并且在页面迭代
一、假设要转换的list为:unitDetalJson 1,在后台代码中将list变成json类型: JSONArray.fromObject(unitDetailList).toString() 2,jsp的迭代代码为: 需要中eval转换 $.each(eval(data.unitDetalJson),function (n,value) { 二、将list在后台迭代放到json里面,假设list为baseProjectList 1,后台代码: getRequest().setCharacterEncoding("utf-8"); JSONArray objs=new JSONArray(); for(int i=0;i<baseProjectList.size;i++){ JSONObject obj=new JSONObject(); obj.put("text",list.get(i).get(xx)); objs.add(obj); } getResponse().getWriter().println(objs.toString()); 2,jsp代码 ajax({ data.xxx }) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |