[英]JqGrid not loading data from JSON
I have a JQGrid plugin in my website, the table is loading OK, but with no-rows to edit, select or whatever.我的网站上有一个 JQGrid 插件,表格加载正常,但没有要编辑、选择或其他任何行的行。 It is requesting the server because when i watch the log I see the request and it's parameters (sidx, _search, rows, sord, nd, etc).
它正在请求服务器,因为当我查看日志时,我看到了请求及其参数(sidx、_search、rows、sord、nd 等)。
This is the jqgrid code:这是 jqgrid 代码:
$(document).ready(function() {
var lastsel;
jQuery("#rowed3").jqGrid(
{
url : CONTEXT_PATH+'/ajax/getPartesByCategory.do?catid=<s:property value="categoryId" />',
datatype: 'json',
colNames : [ 'piezaId', 'descripcion', 'disponible'],
colModel : [ {
name : 'piezaId',
index : 'piezaId',
align : "right",
width : 40
}, {
name : 'descripcion',
index : 'descripcion',
width : 360,
editable : true
}, {
name : 'disponible',
index : 'disponible',
width : 80,
editable : true
} ],
rowNum : 20,
rowList : [ 20, 40, 60, 80 ],
pager : '#prowed3',
sortname : 'id',
viewrecords : true,
sortorder : "desc",
onSelectRow : function(id) {
if (id && id !== lastsel) {
jQuery('#rowed3').jqGrid('restoreRow', lastsel);
jQuery('#rowed3').jqGrid('editRow', id, true);
lastsel = id;
}
},
editurl : "server.php",
caption : "Piezas"
});
jQuery("#rowed3").jqGrid('navGrid', "#prowed3", {
edit : false,
add : false,
del : false
});
})
This is the JSON that the server returns:这是服务器返回的 JSON:
[{
"piezaId": 486,
"disponible": 1,
"descripcion": "Asiento delantero LH",
"category": {
"categoryId": 2,
"category": "Interior",
"status": 1,
"subCategories": []
}
}, {
"piezaId": 485,
"disponible": 1,
"descripcion": "Asiento delantero RH",
"category": {
"categoryId": 2,
"category": "Interior",
"status": 1,
"subCategories": []
}
}]
in the server side I'm using JAVA6, Struts2 and GSon to write the json, but for these ajax calls im only writing to the response a text/plain content在服务器端,我使用 JAVA6、Struts2 和 GSon 来编写 json,但对于这些 ajax 调用,我只向响应写入文本/纯内容
Any help?有什么帮助吗?
You should either change format of data send from the server or use some jsonReader
or jsonmap
technique (see for example jquery with ASP.NET MVC - calling ajax enabled web service or http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data and Mapping JSON data in JQGrid ).您应该更改从服务器发送的数据格式或使用一些
jsonReader
或jsonmap
技术(参见例如jquery 与 ASP.NET MVC - 调用 ajax 启用的 Web 服务或http://www.trirand.com/jqgridwiki/doku.php ?id=wiki:retrieving_data#json_data和在 JQGrid 中映射 JSON 数据)。 The easiest way is to produce data which can be read with the standard jsonReader
(see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data ):最简单的方法是生成可以使用标准
jsonReader
读取的数据(参见http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data ):
{
"total": "1",
"page": "1",
"records": "2",
"rows" : [
{"id" :"1", "cell":["486","1","Asiento delantero LH"]},
{"id" :"2", "cell":["485","1","Asiento delantero RH"]},
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.