问题描述
我一直在尝试使用jqGrid 4.1.2渲染表,我能够从服务器端获取JSON响应,但是我得到了空表。
继承我的样本JSON数据:
I have been trying to render a table using jqGrid 4.1.2, I am able to get the JSON response from server side, but I am getting empty table.Heres my sample JSON data:
{
"response":{
"total":2,
"page":1,
"rows":[{
"id":135060,
"cell":{
"id":135060,
"name":"12"
}
},
{
"id":115060,
"cell":{
"id":115060,
"name":"12345"
}
}
]
},
"status":"SUCCESS",
"errors":[]
}
我添加了 jqgrid-locale-en.js 文件,因此不应该是问题。花了一些时间在这之后我觉得它与jqGrid预期的JSON格式有关,如果那是问题,有人可以告诉我如何配置jqGrid以接受上面的JSON格式。
I have added the the jqgrid-locale-en.js file, so that shouldn't be the issue. After spending some time on this I feel it has something to do with JSON format that jqGrid expects, If thats is the issue, can someone please tell me how to configure jqGrid to accept the the above JSON format.
谢谢!
推荐答案
对于问题仍未解决的情况,这里是解决方案。您应该使用以下 jsonReader
:
For the case that the problem are still not solve here is the solution. You should use following jsonReader
:
jsonReader : {
repeatitems : false,
root: 'response.rows',
page: 'response.page',
total: 'response.page',
records: function (obj) { return obj.response.rows.length; }
}
然后将读取数据(参见)。我想您在JSON数据中使用了错误的总计
属性,而根本没有设置记录
属性。
then the data will be read (see the demo). I suppose that you used incorrect the total
property in the JSON data and not set the records
property at all.
此外,您不应在标准响应中设置错误消息。 HTTP协议支持。如果您在服务器端检测到错误,则服务器应设置。如果jqGrid中的数据处理顺序是并且您应该使用 loadError
事件来解码错误消息并显示用户的结果。
Moreover you should not set error messages inside of the standard response. The HTTP protocol support status codes. If you have detected an error on the server side the server should set error HTTP code in the HTTP header. In the case the order of data processing in the jqGrid does another way and you should use loadError
event to decode the error message and to display the results for the user.
这篇关于jqGrid呈现空表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!