无法使用 jqgrid 加载 json 数据,尽管 jsonstring 工作正常
我有一个 jqgrid,我想用我的 json 填充它,但我无法让它工作。我认为我的 json 很好,因为网格在将 json 作为字符串(数据类型:jsonstring)提供时正在工作。问题是,我没有从 jqgrid 收到任何错误,这使得调试变得困难。
这是我的 json(使用 jslint 验证):
{ "total":"1", "page":"1", "records":"5", "rows": [ {"id" :"1", "cell" :["Modulex", "", "", "", ""]}, {"id" :"2", "cell" :["Lemoltech", "", "", "", ""]}, {"id" :"3", "cell" :["Isothermic", "", "", "", ""]}, {"id" :"4", "cell" :["Renova", "", "", "", ""]}, {"id" :"5", "cell" :["Natart Juvenile", "", "", "", ""]} ] }
这是我的配置
$("#list").jqGrid({
url:'/tempajax/',
datatype: 'json',
colNames:['Nom','Adresse','Ville','Tel','Courriel'],
colModel :[
{name:'company_name', index:'company_name', width:55},
{name:'address', index:'address', width:90},
{name:'city', index:'city', width:90},
{name:'telephone', index:'telephone', width:80},
{name:'email', index:'email', width:80},
],
autowidth: true,
pager: '#pager',
rowNum:10,
viewrecords: true,
gridview: true,
height: '100%'
});
这是我在这里发表的第一篇文章,所以我希望为你们提供足够的信息来帮助你们,如果不仅仅是询问的话。
非常感谢您的帮助!
I have a jqgrid that I'd like to populate with my json, but I can't get it to work. I think my json is fine since the grid is working when supplying the json as a string (datatype:jsonstring). The thing is, I don't get any errors from jqgrid, which makes it hard to debug.
Here's my json (validated with jslint):
{ "total":"1", "page":"1", "records":"5", "rows": [ {"id" :"1", "cell" :["Modulex", "", "", "", ""]}, {"id" :"2", "cell" :["Lemoltech", "", "", "", ""]}, {"id" :"3", "cell" :["Isothermic", "", "", "", ""]}, {"id" :"4", "cell" :["Renova", "", "", "", ""]}, {"id" :"5", "cell" :["Natart Juvenile", "", "", "", ""]} ] }
And here's my config
$("#list").jqGrid({
url:'/tempajax/',
datatype: 'json',
colNames:['Nom','Adresse','Ville','Tel','Courriel'],
colModel :[
{name:'company_name', index:'company_name', width:55},
{name:'address', index:'address', width:90},
{name:'city', index:'city', width:90},
{name:'telephone', index:'telephone', width:80},
{name:'email', index:'email', width:80},
],
autowidth: true,
pager: '#pager',
rowNum:10,
viewrecords: true,
gridview: true,
height: '100%'
});
This is my first post here, so I hope to have supplied enough information for you guys to help, if not just ask.
Thanks a lot for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 JSON 结果与您配置 jqGrid 要使用的内容不匹配。
你的 jqGrid 期望一个 JSON 结果,其中包含 company_name、地址、城市、电话和电子邮件作为字段,但你的数据带回 id 和单元格,即使如此,它也嵌套在顶部 json 结果中,其中包含总计、页面、记录和行。不管怎样,它都没有与你的 jqGrid 对齐。
Your JSON result doesn't match with what you're configuring your jqGrid to consume.
Your jqGrid is expecting a JSON result that has company_name, address, city, telephone, and email as fields, but your data is bringing back id and cell, and even then it's nested inside the top json result, which has total, page, records, and rows. Either way, it's not lined up with your jqGrid.
我解决了我的问题,毕竟 json 没问题。尽管输出良好,但服务器仍抛出 404 代码。这甚至阻止了 jqGrid 解析 json。我希望这对其他人也有帮助!
I fixed my problem, the json was fine afterall. The server was throwing a 404 code, even though the output was good. This prevented jqGrid from even parsing the json. I hope this will be helpfull to others as well!