【发布时间】:2016-01-02 20:13:45
【问题描述】:
我正在构建一个小型应用程序。我有一个 PHP 代码,里面有一个 jqGrid 的创建,还有一个 servlet,它发送一个数组的 string,里面有 JSON。
字符串如下所示:
[
{"id":1,"firstName":"Amishay","lastName":"Vaturi"},
{"id":2,"firstName":"Amir","lastName":"Bilu"},
{"id":3,"firstName":"Michael","lastName":"Keidar"},
{"id":4,"firstName":"Mika","lastName":"Spivak"},
{"id":5,"firstName":"Ksenia","lastName":"Mosorov"},
{"id":6,"firstName":"Rose","lastName":"Wahlem"}
]
问题是我在我制作的网格中没有看到它... 网格代码是这样的:
$("#jqGrid").jqGrid({
url: 'http://10.0.0.4:8080/api/students/all',
mtype: "GET",
datatype: "jsonstring",
colModel: [
{ label: 'ID', name: 'id', key: true, width: 75 , height: 50 },
{ label: 'First Name', name: 'firstName', width: 150 , height: 50},
{ label: 'Last Name', name: 'lastName', width: 150 , height: 50}
],
viewrecords: true,
width: 780,
height: 250,
rowNum: 20,
pager: "#jqGridPager"
});
我在这里和整个网络中寻找答案。 我看到我可能需要从服务器发送不同的 json。也许有更多信息,如记录、页数等。我还看到我可能需要在 jqGrid 属性中声明一个 json 阅读器。 我都做了。。还是不行。就像我没有找到100%解决我的问题的解决方案。 我很高兴得到一个有效的答案(:
非常感谢!
【问题讨论】:
-
HTTP 响应的body 通常是一个字符串。因此,如果您想从
url加载数据,则必须使用datatype: "json"而不是datatype: "jsonstring"。我在答案中发布了更多详细信息。