jqgrid addJSONData不起作用 [英] jqgrid addJSONData doesn't work
问题描述
我正在使用jqGrid,返回的json是
{"total":1,"page":1,"records":2,"rows":[{"projectId":"1022","name":"john"}]}
然后在我调用的函数中
var jsongrid = eval("("+data+")");
var thegrid = jQuery("#projectList")[0];
thegrid.addJSONData(jsongrid);
但是它给我错误:object为null或未定义.不知道为什么.我没有使用json阅读器.
顺便说一句,您知道如何使用set方法设置总计",页面",记录"吗?
我想您尝试在 之前调用addJSONData
方法 >
几乎不需要使用 在演示中,我仅从示例中获得了表格用法 jQuery.serialize 并对其进行一些修改.它显示您需要的数据 此外,就像您可以轻松验证Fiddler或Firebug一样,URL还会附加以下附加参数 标准参数 将附加表格中的参数 在某些情况下,可以选择使用 jQuery.serializeArray .它允许以另一种格式(例如JSON)序列化数据或以另一种格式转换数据(请参见此处),可以使用 $ .extend 与标准jqGrid参数轻松合并. I am working on jqGrid, the return json is then in the function I call but it give me error: object is null or undefined. don't know why . I didn't use json reader. BTW, do you know how to use set method to set "total", "page", "records" ? I suppose that you try to call The usage of I suppose that you should use UPDATED: From your previous question it seems that you want just send additional data to the server from the form on clicking of the "Search" button. In the case I would suggest to modify the code to the following In the demo I get just the form from the example of the usage jQuery.serialize and modify it a little. It display the data which you need Additionally, like you can easy verify with respect of Fiddler or Firebug, the URL will ba appended with additional parameters like below The standard parameters will be appended with parameters from the form In some scenarios one can use jQuery.serializeArray alternatively. It allows to serialize the data in another format (like JSON) or convert the data in some another format (see here) which can be easy merged with the standard jqGrid parameters using $.extend. 这篇关于jqgrid addJSONData不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!addJSONData
(请参阅我的第一篇有关主题的文章此处).同样,您永远都不要使用邪恶的eval
方法.一个使用 jQuery.parseJSON 或var $grid = $("#projectList");
$grid.jqGrid({
url: 'user595234.json',
datatype: "json",
serializeGridData: function (data) {
return $.param(data) + '&' + $("#project_search_form").serialize();
},
jsonReader: {id: "projectId", repeatitems: false},
colNames: ['ID', 'Name'],
colModel: [
{name: 'projectId', width: 255},
{name: 'name', width: 255}
],
rowNum: 10,
rowList: [10,20,30],
pager: '#projectPager',
sortname: 'projectId',
viewrecords: true,
sortorder: "desc",
caption: "Simple data manipulation",
height: "auto"
}).jqGrid("navGrid", "#projectPager", {edit: false, add: false, del: false});
$("#search").click(function () {
$grid.trigger("reloadGrid", [{page: 1}]);
});
...?_search=false&nd=1336057299806&rows=10&page=1&sidx=projectId&sord=desc&a=1&b=2&c=3&d=4&e=7&f=8
_search=false&nd=1336057299806&rows=10&page=1&sidx=projectId&sord=desc
a=1&b=2&c=3&d=4&e=7&f=8
{"total":1,"page":1,"records":2,"rows":[{"projectId":"1022","name":"john"}]}
var jsongrid = eval("("+data+")");
var thegrid = jQuery("#projectList")[0];
thegrid.addJSONData(jsongrid);
addJSONData
method before the grid will be created with respect of jQuery("#projectList").jqGrid({...});
addJSONData
is practically always unneeded (see one from my first posts about the subject here). In the same way you should never use eval
method which is evil. One uses jQuery.parseJSON or JSON.parse instead.datatype: 'json'
to solve your problem. You should post more code to show you how you should use other jqGrid options in your case.var $grid = $("#projectList");
$grid.jqGrid({
url: 'user595234.json',
datatype: "json",
serializeGridData: function (data) {
return $.param(data) + '&' + $("#project_search_form").serialize();
},
jsonReader: {id: "projectId", repeatitems: false},
colNames: ['ID', 'Name'],
colModel: [
{name: 'projectId', width: 255},
{name: 'name', width: 255}
],
rowNum: 10,
rowList: [10,20,30],
pager: '#projectPager',
sortname: 'projectId',
viewrecords: true,
sortorder: "desc",
caption: "Simple data manipulation",
height: "auto"
}).jqGrid("navGrid", "#projectPager", {edit: false, add: false, del: false});
$("#search").click(function () {
$grid.trigger("reloadGrid", [{page: 1}]);
});
...?_search=false&nd=1336057299806&rows=10&page=1&sidx=projectId&sord=desc&a=1&b=2&c=3&d=4&e=7&f=8
_search=false&nd=1336057299806&rows=10&page=1&sidx=projectId&sord=desc
a=1&b=2&c=3&d=4&e=7&f=8