Extjs4form load()后台数据的json格式,与grid load()后台数据的格式

首先感谢 该博主 http://blog.sina.com.cn/s/blog_737a9d990100ui1v.html

Extjs的数据解析以json格式为主,SQL查询之后的结果集一般为Collections/List,

1.GRID

想转换成json格式返给前台需要借助第三方类库(json-lib-2.4-jdk15.jar,json-simple.jar)

若service层返回List,则做此处理,(list为service返回的查询结果集)

1             JSONArray jsonList = JSONArray.fromObject(list, jsonConfig);
2             String resText = "{success:true,data:" + jsonList.toString()
3                     + ",totalCount:" + listAll.size() + "}";
4             out.write(resText);

该代码返回的resText是这样的,请注意格式  data:[{......}]

1 resultText : {success:true,data:[{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":3,"high1":0,"high2":0,"id":"10","limit":0,"low":1,"low1":0,"low2":0,"remarks":"2","start":0,"userId":"1","userName":""},{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":120,"high1":0,"high2":0,"id":"11","limit":0,"low":80,"low1":0,"low2":0,"remarks":"3","start":0,"userId":"1","userName":""},{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":110,"high1":0,"high2":0,"id":"12","limit":0,"low":70,"low1":0,"low2":0,"remarks":"123","start":0,"userId":"1","userName":""},{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":3,"high1":0,"high2":0,"id":"2","limit":0,"low":1,"low1":0,"low2":0,"remarks":"4","start":0,"userId":"1","userName":""},{"examTime":"2013-12-03 00:00:00","examTimeEnd":null,"examTimeStart":null,"high":123,"high1":0,"high2":0,"id":"2013/12/03 00:00:00_1","limit":0,"low":123,"low1":0,"low2":0,"remarks":"123","start":0,"userId":"1","userName":""},{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":3,"high1":0,"high2":0,"id":"7","limit":0,"low":1,"low1":0,"low2":0,"remarks":"agasdf","start":0,"userId":"1","userName":""},{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":3,"high1":0,"high2":0,"id":"8","limit":0,"low":1,"low1":0,"low2":0,"remarks":"按时吃饭","start":0,"userId":"1","userName":""},{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":3,"high1":0,"high2":0,"id":"9","limit":0,"low":1,"low1":0,"low2":0,"remarks":"remarks","start":0,"userId":"1","userName":""}],totalCount:8}

2.FORM

如果要用form从后台load数据,步骤大致相同,但是返回数据的格式稍作变化,注意格式  data:{.....}

1 JSONArray jsonList = JSONArray.fromObject(p,jsonConfig);
2 String resText = "{success:true,data:" + jsonList.toString()+"}";
3 resText = resText.replace("[","");
4 resText = resText.replace("]","");

原格式无法在form中显示

resultText : {success:true,data:{"examTime":"2013-12-24 15:50:37","examTimeEnd":null,"examTimeStart":null,"high":110,"high1":0,"high2":0,"id":"12","limit":0,"low":70,"low1":0,"low2":0,"remarks":"123","start":0,"userId":"1","userName":""}}

效果如图所示,还有瑕疵,需继续补充,先留草稿

原文地址:https://www.cnblogs.com/dirkmurphyjava/p/3493166.html