简体   繁体   English

jqgrid从rest服务检索JSON数据,但不显示它

[英]jqgrid retrieves JSON data from rest service but does not display it

The grid displays and retrieves the data from the rest service but does not show up. 网格显示并从其余服务检索数据,但未显示。 I'm pretty sure I'm just missing something stupid but I've checked the documentation and a few other answers on here and nothing has fixed it. 我敢肯定,我只是缺少一些愚蠢的东西,但是我在这里检查了文档和其他一些答案,没有任何东西可以解决。 I can see in the debugger the data is coming across (which is where I pulled the sample from) and there are no JavaScript errors on the page. 我可以在调试器中看到遇到的数据(这是我从中提取示例的位置),并且页面上没有JavaScript错误。 I also checked the data and it's valid JSON. 我还检查了数据,它是有效的JSON。 What am I missing/doing wrong? 我想念/做错了什么?

Code: 码:

<table id="custSearch">
    <tr><td></td></tr>
</table>
<div id="custSearchPager"></div>

 $("#custSearch").jqGrid({ url : '/rebate/rest/customer/getCustomers', datatype : 'json', mtype : 'GET', colNames : ['customerID', 'Company', 'First Name', 'Last Name','Address', 'City', 'State', 'Zip Code', 'Phone', 'Fax', 'EMail'], colModel : [ { name:'customerID', index:'customerID', width:10, sortable:false, editable: false, hidden: true}, { name:'Company', index:'company', width:150, sortable:true}, { name: 'First Name', index: 'firstName', length: 50, search: false}, { name: 'Last Name', index: 'lastName', width: 80}, { name: 'Address', index: 'address', width: 100, search: false}, { name: 'City', index: 'city', width: 40, search: false}, { name: 'State', index: 'state', width: 80, search: false, edittype: 'select', editoptions: { dataUrl:'/rebate/rest/state/getLookups'} }, { name: 'Zip', index: 'zip', width: 80}, { name: 'Phone', index: 'phone', width: 80}, { name: 'Fax', index: 'fax', width: 80, search: false}, { name: 'EMail', index: 'email', width: 80} ], rowNum: 20, rowList:[10,20,30], pager : '#custSearchPager', sortname : 'company', sortorder : 'desc', viewrecords: true, gridview: true, caption : 'Customers', height: '300', jsonReader: {cell:"", id:"customerID"} }); jQuery("#custSearch").jqGrid('navGrid','#custSearchPager',{edit:false,add:false,del:false,search:true}); 

Data: 数据:

{"page":"1","total":"30","records":"20","rows":[
    {"customerID":144,"firstName":"Keefe","lastName":"Abbott","company":"Vulputate LLC","address":"P.O. Box 688, 4718 Urna Street","country":"USA","city":"Detroit","state":"MI","zip":"61733","phone":"(411) 256-3885","fax":"(712) 531-0718","email":"Etiam@Integereu.org"},
    {"customerID":91,"firstName":"Jerome","lastName":"Allison","company":"Vulputate Inc.","address":"Ap #519-7407 Orci Road","country":"USA","city":"Kansas City","state":"MO","zip":"22551","phone":"(245) 214-4028","fax":"(202) 531-5933","email":"sed.dolor.Fusce@risusDonec.ca"},
    {"customerID":293,"firstName":"Hyacinth","lastName":"Fuentes","company":"Vulputate Corporation","address":"Ap #899-7402 Donec Road","country":"USA","city":"Jackson","state":"MS","zip":"27829","phone":"(342) 945-6263","fax":"(260) 216-3339","email":"felis.Donec.tempor@sitamet.org"},
    {"customerID":235,"firstName":"Charde","lastName":"England","company":"Vulputate Associates","address":"2803 Odio Street","country":"USA","city":"Racine","state":"WI","zip":"17971","phone":"(421) 324-5019","fax":"(559) 946-7839","email":"pretium@eu.org"}
. . .
]}

The names in colModel can't contain spaces. colModel中的名称不能包含空格。 I think you have mixed the name and the label property in colModel to display headers of the table. 我认为您已经在colModel中混合了name和label属性,以显示表的标题。

The wrong in your code is that the name property does not match the data from the response and second your name property contain space, which is not allowed. 您的代码中的错误是name属性与响应中的数据不匹配,并且您的name属性包含空格,这是不允许的。 To work this your colModel should be: 为此,您的colModel应该为:

colModel : [ 
    { name:'customerID', label:'customerID', index:'customerID', width:10, sortable:false, editable: false, hidden: true},
    { name:'company', label:'Company', index:'company', width:150, sortable:true},
    { name: 'firstName', label: 'First Name', index: 'firstName', length: 50, search: false},   
    { name:'lastName', label: 'Last Name', index: 'lastName', width: 80}, 
    { name: 'address', label: 'Address', index: 'address', width: 100, search: false}, 
    { name: 'city', label: 'City', index: 'city', width: 40, search: false}, 
    { name:'state', label: 'State', index: 'state', width: 80, search: false, edittype: 'select', editoptions: { dataUrl:'/rebate/rest/state/getLookups'} }, 
    { name:'zip', label: 'Zip', index: 'zip', width: 80}, 
    { name:'phone', label: 'Phone', index: 'phone', width: 80}, 
    { name: 'fax', label: 'Fax', index: 'fax', width: 80, search: false}, 
    { name: 'email', label: 'EMail', index: 'email', width: 80}
],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM