Jquery jqGrid json数据
您好,我有一个正常工作的示例:Jquery jqGrid json数据,jquery,jqgrid,Jquery,Jqgrid,您好,我有一个正常工作的示例: $(function() { $("#treegrid").jqGrid({ url: 'tree2.json', datatype: 'json', mtype: 'GET', colNames: ["ID", "Description", "Total"], colModel: [{ name: 'id
$(function() {
$("#treegrid").jqGrid({
url: 'tree2.json',
datatype: 'json',
mtype: 'GET',
colNames: ["ID", "Description", "Total"],
colModel: [{
name: 'id',
index: 'id',
width: 1,
hidden: true,
key: true
}, {
name: 'desc',
index: 'desc',
hidden: false,
sortable: true
}, {
name: 'num',
index: 'num',
hidden: false,
sortable: true
}],
height: 'auto',
width: '500',
pager: "#ptreegrid",
caption: "Tree Grid Example"
})
});
JSON数据
{
"page": 1,
"total": 1,
"records": 2,
"rows": [
{"id": 1, "cell": ["1", "Source 1", "300"]},
{"id": 2, "cell": ["2", "Source 2", "100"]}
]
}
如何命令jqGrid读取这种类型的JSON数据?可能吗
{
"page": 1,
"total": 1,
"records": 2,
"rows": [
{"id": 1, "cell": {"id":"1", "desc":"Source 1", "num":"300"}},
{"id": 2, "cell": {"id":"2", "desc":"Source 2", "num":"100"}}
]
}
就这些
不要读下一行
抱歉,这是一些要通过警报查看的文本:)
哎呀!无法提交您的问题,因为:
你的文章没有太多的上下文来解释代码部分;请更清楚地解释你的情况
================
谢谢你的帮助
我的最终版本也取自你的答案
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
我已经更改了JSON数据
[
{"id":"1", "desc":"Source 1", "num":"300"},
{"id":"2", "desc":"Source 2", "num":"100"}
]
[
{"id":"1", "desc":"Source 1", "num":"300"},
{"id":"2", "desc":"Source 2", "num":"100"}
]
非常感谢 您可能指的是数据格式:
{
“页码”:1,
“总数”:1,
“记录”:2,
“行”:[
{“id”:“1”,“desc”:“Source 1”,“num”:“300”},
{“id”:“2”,“desc”:“Source 2”,“num”:“100”}
]
}
没有重复的id
和不需要的单元格
属性。要读取数据,您需要包括jqGrid的jsonReader:{repeatitems:false}
选项(请参阅)。谢谢您的帮助
我的最终版本也取自你的答案
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
jsonReader: {
repeatitems: false,
root: function (obj) { return obj; },
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
我已经更改了JSON数据
[
{"id":"1", "desc":"Source 1", "num":"300"},
{"id":"2", "desc":"Source 2", "num":"100"}
]
[
{"id":"1", "desc":"Source 1", "num":"300"},
{"id":"2", "desc":"Source 2", "num":"100"}
]
非常感谢 你最好在问题的正文中附加这样的信息,而不是发布新的答案。它简化了其他访问者对问题的阅读。此外,你还应该给出最有助于解决问题的答案。我还建议您阅读语法突出显示,并比较您的问题和我的答案代码中的颜色。我建议您在所有jqgrid问题中添加“jquery”标记。现在您可以删除答案了。