浏览 6096 次
锁定老帖子 主题:EXT读取后台json数据的问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-10-30
大侠们帮忙看看吧 ~~~ 后台能取到数据,可前台怎么都取不到json,页面上能显示出grid框和列 但是没有数据;大家看我的代码可能会发现我的列都是中文的,这是由于我们的项目的原因,我查过资料EXT对中文取值是支持的 我的jsp也是UTF-8的 json的后台打印:{"pageInfo":1,"data":[{"签发人":"","归档":"","登记号":"001","保管期限":"10年","文件标题":"关于什么的测试情况","原文路径":"","份数":"","主题词":"啊","备注":"","正文":"","归档份数":"","处理单":"","密级":"机密","责任者":"啊","拟稿人":"","办结提示":"","分类号":"020","成文日期":"20081009","页数":"1","全宗号":"","缓急程度":"","签发时间":"","拟稿部门":"","主办部门":"","文号":"综[2008]1号","附件":"","登记日期":"20081009"}]} java(action)的写法: JSONArray ary = new JSONArray(recodList); JSONObject jo = new JSONObject(); jo.put("data", ary); jo.put("pageInfo",recodList.size()); String jstr=jo==null?"":jo.toString(); boolean scriptTag = false; String cb = request.getParameter("callback"); if (cb != null) { scriptTag = true; response.setContentType("text/html;charset=UTF-8"); } else {//"text/html;charset=UTF-8" "text/javascript;charset=UTF-8" "application/x-json;charset=UTF-8" response.setContentType("text/html;charset=UTF-8"); } if (scriptTag) { jstr = cb + "("+jstr+")"; } System.out.println(jstr); response.getWriter().print(jstr); jsp(js代码) <html> <head> <link rel="stylesheet" type="text/css" href="scripts/ext/resources/css/ext-all.css" /> <script type="text/javascript" src="scripts/ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="scripts/ext/ext-all.js"></script> <script type="text/javascript" src="scripts/ext/ext-all-debug.js"></script> <script type="text/javascript" src="scripts/ext/source/locale/ext-lang-zh_CN.js"></script> <script type="text/javascript" > var APP_PATH='/esoaisapp'; Ext.onReady(function(){ function toggleDetails(btn, pressed){ var view = grid.getView(); view.showPreview = pressed; view.refresh(); } var ds= new Ext.data.Store({ proxy: new Ext.data.HttpProxy({url: "listPreArchiveEdit.html?content.method=TestGtSearch&contentPath=/preArchive/1@2/1@299/29@332/4@346/3@456/@458"}), reader: new Ext.data.JsonReader({ totalProperty:"pageInfo", root:"data", fields:[ {name:"密级"}, {name:"办结提示"}, {name:"成文日期"}, {name:"附件"}, {name:"责任者"}, {name:"拟稿部门"}, {name:"签发时间"}, {name:"保管期限"}, {name:"登记号"}, {name:"全宗号"}, {name:"登记日期"}, {name:"分类号"}, {name:"主题词"}, {name:"主办部门"}, {name:"份数"}, {name:"归档"}, {name:"拟稿人"}, {name:"签发人"}, {name:"页数"}, {name:"文件标题"}, {name:"原文路径"}, {name:"文号"}, {name:"缓急程度"}, {name:"备注"}, {name:"归档份数"}, {name:"正文"}, {name:"处理单"} ] }) }); var cbsm=new Ext.grid.CheckboxSelectionModel(); var cm=new Ext.grid.ColumnModel( [new Ext.grid.RowNumberer(), cbsm, {header:"密级",dataIndex:"密级"}, {header:"办结提示",dataIndex:"办结提示"}, {header:"成文日期",dataIndex:"成文日期"}, {header:"附件",dataIndex:"附件"}, {header:"责任者",dataIndex:"责任者"}, {header:"拟稿部门",dataIndex:"拟稿部门"}, {header:"签发时间",dataIndex:"签发时间"}, {header:"保管期限",dataIndex:"保管期限"}, {header:"登记号",dataIndex:"登记号"}, {header:"全宗号",dataIndex:"全宗号"}, {header:"登记日期",dataIndex:"登记日期"}, {header:"分类号",dataIndex:"分类号"}, {header:"主题词",dataIndex:"主题词"}, {header:"主办部门",dataIndex:"主办部门"}, {header:"份数",dataIndex:"份数"}, {header:"归档",dataIndex:"归档"}, {header:"拟稿人",dataIndex:"拟稿人"}, {header:"签发人",dataIndex:"签发人"}, {header:"页数",dataIndex:"页数"}, {header:"文件标题",dataIndex:"文件标题"}, {header:"原文路径",dataIndex:"原文路径"}, {header:"文号",dataIndex:"文号"}, {header:"缓急程度",dataIndex:"缓急程度"}, {header:"备注",dataIndex:"备注"}, {header:"归档份数",dataIndex:"归档份数"}, {header:"正文",dataIndex:"正文"}, {header:"处理单",dataIndex:"处理单"} ] ); var grid=new Ext.grid.GridPanel({el:"grid",store:ds,cm:cm,sm:cbsm, width:800, height:500, title:"grid", bbar: new Ext.PagingToolbar({ pageSize: 4, store: ds, displayInfo: true, displayMsg: "Displaying topics {0} - {1} of {2}", emptyMsg: "No topics to display" }) }); grid.render(); ds.load({params:{start:0,limited:10}}); }); </script> </head> <body style="padding:0px;margin:10px;"> <div id="grid" style="border:0px solid #cccccc;background-color:#f3f3f3;padding:5px;width:100%;" > </div> </body> </html> 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-10-31
大侠们帮帮忙吧
|
|
返回顶楼 | |
发表时间:2008-10-31
你在浏览器里面直接访问“listPreArchiveEdit.html?content.method=TestGtSearch&contentPath=/preArchive/1@2/1@299/29@332/4@346/3@456/@458”这个地址页面能出来json字符串么?
给你看看我的做法(我用的SpringMVC,其他的应该类似): JSONArray jsonArray = JSONArray.fromObject(list); Map<String,Object> modle = new HashMap<String,Object>(); modle.put("size", size); modle.put("grid", jsonArray); mav.addObject("model", modle); return mav; 然后action跳转到jsp: <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%> <%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%> {"totalCount":"<c:out value="${model.size}" escapeXml='false'/>","topics":<c:out value="${model.grid}" escapeXml='false'/>} |
|
返回顶楼 | |
发表时间:2008-10-31
原因找到了 我们用了sitemath 来修饰页面 它会修改response的内容 将sitemath对此页面的修饰去掉就可以了
非常感谢 |
|
返回顶楼 | |
发表时间:2008-11-12
不是吧,我也用siteMesh,但是返回的json格式的response没变啊
|
|
返回顶楼 | |
发表时间:2008-11-12
我怎在做这个demo,借鉴你的,先看看
|
|
返回顶楼 | |