首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

jqGrid分页加载json数据无法显示的有关问题

2012-06-29 
jqGrid分页加载json数据无法显示的问题版本:jqgrid-4.3.2html代码:table idprdDetailTbl/table di

jqGrid分页加载json数据无法显示的问题

版本:jqgrid-4.3.2

html代码:

<table id="prdDetailTbl"></table> <div id="prdPageDiv"></div>

?

?

?

?

?页面js代码:

jQuery("#prdDetailTbl").GridUnload();jQuery("#prdDetailTbl").jqGrid({ url:'getProductOrderDetails.do?prdBranchId='+prdBranchId, datatype: "json", colNames:['订单号','结算单价', '数量', '结算总价'], colModel:[ {name:'orderId',width:55},            {name:'settlePrice',width:90},            {name:'quantity', width:100},            {name:'settleAmount',width:100}          ],            jsonReader: {         repeatitems:false,          rows: "rows",               // 数据行(默认为:rows)          total: "total",        // 总记录数          page: "page",            // 当前页          records: "records"    // 总记录数          },rowNum:10, rowList:[10,20,30], pager: '#prdPageDiv', sortname: 'id', viewrecords: true, sortorder: "desc"}); jQuery("#prdDetailTbl").jqGrid('navGrid','#prdPageDiv',{edit:false,add:false,del:false});

??

?

?

?action中输出的mime类型json:

this.getResponse().setContentType("application/json;charset=UTF-8");this.getResponse().setCharacterEncoding("UTF-8");try {PrintWriter out = this.getResponse().getWriter();out.write(json);out.flush();out.close();} catch (Exception e) {e.printStackTrace();}

??

?之前在??? jsonReader中没有设置 repeatitems:false,页面上一直无法显示数据。然后用firebug一步一步调试,if (dReader.repeatitems) {if(dReader.cell) {cur = $.jgrid.getAccessor(cur,dReader.cell);}if (!F) { F=orderedCols(gi+si+ni); }}

??

?如果没有设置repeatitems:false,则cur会被重新赋值,如果cur中没有cell属性值,则$.jgrid.getAccessor(cur,dReader.cell)会返回undefined,这样就导致页面无法显示数据,还报一个obj undefined的错。

总结:jqgrid加载json数据时,需要设置jsonReader的repeatitems:false。当然,如果返回的数据中有cell属性值,应该也可以显示(这种用法没测试过)。

?

?

?

?

热点排行