Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jqGrid呈现空表_Javascript_Jquery_Json_Jqgrid - Fatal编程技术网

Javascript jqGrid呈现空表

Javascript jqGrid呈现空表,javascript,jquery,json,jqgrid,Javascript,Jquery,Json,Jqgrid,我一直在尝试使用jqGrid 4.1.2呈现一个表,我能够从服务器端获得JSON响应,但得到的是空表。 下面是我的JSON数据示例: { "response":{ "total":2, "page":1, "rows":[{ "id":135060, "cell":{ "id":135060, "n

我一直在尝试使用jqGrid 4.1.2呈现一个表,我能够从服务器端获得JSON响应,但得到的是空表。 下面是我的JSON数据示例:

{
    "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格式


谢谢

默认情况下,jqGrid不希望单元格键中的数据包含name:value对。如果您想使用name:value配对,那么您需要研究如何使用jsonReader选项并将repeatitems设置为false。还要确保每个键的名称与相应的colModel名称完全相同

没有更多的代码很难说。当你问这样的问题时,你应该发布你所有的代码,但是试着用这样的方式,以及你正在设置的任何其他选项

$("#id").jqGrid({
    url: "url"
    mtype: "post",
    datatype: "json",
    jsonReader: {
        repeatitems: false,
        root: "response.rows",
        cell: "cell",
        id: "id",
        page: "page",
        total: "total",
        records: "records"
    },  
});

看起来您也没有传回records键,这是服务器端调用返回的总行数

,如果问题仍然没有解决,这里是解决方案。您应该使用以下
jsonReader

jsonReader : {
    repeatitems : false,
    root: 'response.rows',
    page: 'response.page',
    total: 'response.page',
    records: function (obj) { return obj.response.rows.length; }
}
然后将读取数据(请参阅)。我假设您在JSON数据中使用了不正确的
total
属性,并且根本没有设置
records
属性

此外,您不应该在标准响应中设置错误消息。HTTP协议支持。如果在服务器端检测到错误,则应在HTTP头中设置服务器。如果jqGrid中的数据处理顺序不正确,则应使用
loadError
事件解码错误消息并向用户显示结果