jqgrid custom JSON data 没有错误但不显示数据

jqgrid custom JSON data no error but not showing data

我使用 jqGrid 已经有一段时间了,我只是想创建一个新的服务器端脚本来 return 数据到客户端网格。很多时候我试图回到这些软件程序的基础知识。我想 return JSON 数据到我的网格,只加载一次没有寻呼机。参考文档 here 后,我尝试创建 JSON 字符串以匹配文档中的格式,如下所示:

{ 
  "total": "xxx", 
  "page": "yyy", 
  "records": "zzz",
  "rows" : [
    {"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
    {"id" :"2", "cell":["cell21", "cell22", "cell23"]},
      ...
  ]
}

这是 JS 网格定义:

$("#jqGrid").jqGrid({
    url:'/dataurl.php',
    shrinkToFit: true,
    autowidth: true,
    datatype: 'json',
    mtype: 'POST',
    postData:{
        'arg1':'load_data',
        'num_days':$('#num_of_days_input').val()
    },
    colNames:[
        'Ship_Date',
        'Insert/Label',
        'Customer',
        'JobNum',
        'QNTYOrdered',
        'DEL',
        'Ship_Type',
        'Carrier',
        'Time',
        'Status'
    ],
    colModel:[
        {width:20,name:'Ship_Date', index:'Ship_Date'},
        {width:20,name:'InsertorLabel', index:'InsertorLabel'},
        {width:20,name:'Customer', index:'Customer'},
        {width:20,name:'JobNum', index:'JobNum'},
        {width:20,name:'QNTYOrdered', index:'QNTYOrdered'},
        {width:20,name:'DEL', index:'DEL'},
        {width:20,name:'Ship_Type', index:'Ship_Type', edittype:'select', editoptions:{value:"Partial:Partial;Balance:Balance;Full:Full"}},
        {width:20,name:'Carrier', index:'Carrier', edittype:'select', editoptions:{value:"UPS:UPS;Fed Ex:Fed Ex;2D:2D;T&M:T&M;Cougar:Cougar"}},
        {width:20,name:'Time', index:'Time', edittype:'select', editoptions:{value:"before 7am:before 7am;7-9am:7-9am;9-12am:9-12am;12-3pm:12-3pm;after 3pm:after 3pm"}},
        {width:20,name:'Status', index:'Status', edittype:'select', editoptions:{value:"To Ship:To Ship;Ship Pending:Ship Pending"}}
    ],
    loadonce: true,
    sortname: 'Ship_Date',
    sortorder: 'asc',
    viewrecords: true,
    gridview: true,
    caption: 'Shipping Request',
    loadError: function(xhr, status, error){
        alert(xhr.responseText);
        alert(status);
        alert(error);
    },
    loadComplete: function(data){
        alert(JSON.stringify(data, null, 4));
    }
});

我已经使用 loadError 方法进行了相当多的调试,现在我没有收到任何错误,我可以看到我从服务器 return 编辑的数据。在我看来格式是正确的:

但是,遗憾的是,那里的网格仍然是空的。我还缺少什么吗?谢谢!

服务器 JSON 响应的 rows 属性 的值 必须是数组 ,但您使用对象代替 (它应该是 "rows": [{}],但你使用 "rows": {} 代替)。即使您只有一项,您仍然应该 return 包含其中一项的数组。