初めてjqgridを使用する問題
8039 ワード
ネット上でNの例を探して試してみましたが、毎回フロントfirebugでjosnデータが届いているのが見えますが、jqgridではデータがありません.
今日josnデータの中の単一引用符を、すべて二重引用符に置き換えて、データがやっと表示されました.
jqgridは意外にも単引用符を認識しません!!!
これは三日間もやったのに、なんとこれのせいだ...うっとうしい!
JAvaバックグラウンドコードは以下の通りです.
勝手に書いたテストコードは、散らかっています...
受信したjosnデータ:
ここの辺の二重引用符を一重引用符データに変えると表示できません!!!怪しい.
今日josnデータの中の単一引用符を、すべて二重引用符に置き換えて、データがやっと表示されました.
jqgridは意外にも単引用符を認識しません!!!
これは三日間もやったのに、なんとこれのせいだ...うっとうしい!
<%@ page contentType="text/html;charset=utf-8"%>
<link rel="stylesheet" type="text/css" href="public/lib/jquery/css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="public/lib/jquery/css/ui-lightness/jquery-ui-1.8.9.custom.css" />
<script src="public/lib/jquery/js/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="public/lib/jquery/js/i18n/grid.locale-cn.js" type="text/javascript"></script>
<script src="public/lib/jquery/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<html>
<head>
<title>ALOES</title>
<script type="text/javascript">
$(document).ready(function(){
jQuery("#jsonmap").jqGrid({
url : 'eventAction.do?method=getEvents',
datatype : "json",
colNames:['EventID','CUID', 'Date', 'Severity','EventType','Description'],
colModel:[
{name:'eventID',index:'eventID', width:60},
{name:'cuid',index:'cuid', width:90},
{name:'eventTime',index:'eventTime', width:100},
{name:'severity',index:'severity', width:80, align:"right"},
{name:'eventType',index:'eventType', width:80, align:"right"},
{name:'description',index:'description', width:80,align:"right"}
],
imgpath: '/public/images',
rowNum:10,
rowList:[10,20,30],
pager: "pjmap",
multiselect: false,
sortname: 'eventID',
viewrecords: true,
sortorder: "desc",
jsonReader: {
root: "events",
repeatitems : false
},
caption: "jqGrid test",
loadComplete:function(){ //
var n = $('#gridTable').getGridParam('records'); //
//alert(n);
},
width:800,
height: 220
}).navGrid('pjmap',
{view:true,edit:true,add:false,del:false},
{closeOnEscape:true}
);
});
</script>
</head>
<body>
<table id="jsonmap" ></table>
<div id="pjmap" ></div>
</body>
</html>
JAvaバックグラウンドコードは以下の通りです.
勝手に書いたテストコードは、散らかっています...
public void getEvents(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
StringBuffer str = new StringBuffer();
//
DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
List eventList = eventService.getEvents();
str.append("{\"events\":[");
if (eventList != null && eventList.size()> 0) {
//for(Iterator iter = eventList.iterator();iter.hasNext();){
for(int i=0;i<10;i++){
Event event = (Event)eventList.get(i);
str.append("{\"eventID\":"+"\""+event.getEventID()+"\",");
str.append("\"cuid\":"+"\""+event.getCuid()+"\",");
str.append("\"eventTime\":"+"\""+format1.format(event.getEventTime())+"\",");
str.append("\"severity\":"+"\""+event.getSeverity()+"\",");
str.append("\"eventType\":"+"\""+event.getEventType()+"\",");
String dec = stringFilter(event.getDescription());
str.append("\"description\":"+"\""+dec+"\"}");
/* if(iter.hasNext()){
str.append(",");
}*/
if(i<9){
str.append(",");
}
}
}
//str.substring(0,str.length()-1);
str.append("],\"page\":1,\"rows\":10,\"total\":10}");
} catch(Exception e){
logger.error(" !",e);
}
response.setContentType(" text/josn;charset=utf-8 ");
PrintWriter out = response.getWriter();
out.println(str);
out.flush();
}
受信したjosnデータ:
{
"events":[
{"eventID":"1298878203692","cuid":"HP-3.125","eventTime":"2011-02-28 15:30:03","severity":"3","eventType":"Probe","description":" Connection refused"},
{"eventID":"1298878202225","cuid":"HP-3.125","eventTime":"2011-02-28 15:30:02","severity":"3","eventType":"Probe","description":"Connection refused"},
{"eventID":"1298878201201","cuid":"HP-3.125","eventTime":"2011-02-28 15:30:01","severity":"3","eventType":"Probe","description":" Connection refused"},
{"eventID":"1298877903783","cuid":"HP-3.125","eventTime":"2011-02-28 15:25:03","severity":"3","eventType":"Probe","description":"Connection refused"},
{"eventID":"1298877902365","cuid":"HP-3.125","eventTime":"2011-02-28 15:25:02","severity":"3","eventType":"Probe","description":" Connection refused"},
{"eventID":"1298877901326","cuid":"HP-3.125","eventTime":"2011-02-28 15:25:01","severity":"3","eventType":"Probe","description":"Connection refused"},
{"eventID":"1298867776540","cuid":"HP-3.125","eventTime":"2011-02-28 12:36:16","severity":"3","eventType":"Probe","description":"No route to host"},
{"eventID":"1298867776521","cuid":"Dell-31","eventTime":"2011-02-28 12:36:16","severity":"3","eventType":"Probe","description":"Connection timed out"},
{"eventID":"1298867776463","cuid":"HP-3.125","eventTime":"2011-02-28 12:36:16","severity":"3","eventType":"Probe","description":"Connection timed out"},
{"eventID":"1298867774532","cuid":"HPGroup","eventTime":"2011-02-28 12:36:14","severity":"3","eventType":"Probe","description":"Connection timed out"}],
"page":1,"rows":10,"total":10
}
ここの辺の二重引用符を一重引用符データに変えると表示できません!!!怪しい.