动态加载JQGrid数据时, 一般使用xml或json格式,这2种格式的默认如下:
XML数据:
jQuery("#gridid").jqGrid({
...
xmlReader : {
root: "rows",
row: "row",
page: "rows>page",
total: "rows>total",
records : "rows>records",
repeatitems: true,
cell: "cell",
id: "[id]",
userdata: "userdata",
subgrid: {
root:"rows",
row: "row",
repeatitems: true,
cell:"cell"
}
},
...
});
JSON数据:
JSON对象是一个无序的“‘名称/值’对”集合。一个对象以“{”(左括号)开始,“}”(右括号)结束。每个“名称”后跟一个“:”(冒号);“‘名称/值’ 对”之间使用“,”(逗号)分隔。
jQuery("#gridid").jqGrid({
...
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true,
cell: "cell",
id: "id",
userdata: "userdata",
subgrid: {
root:"rows",
repeatitems: true,
cell:"cell" }
},
...
});
在软件开发中,json格式以其简洁、数据量小而更常用。生成的json数据格式例子如下:
{"rows":[{"remark":"","no":"","moduleName":"系统参数","_name":"表格","parent":"系统参数","expanded":false
,"type":"int","section":"表格","id":10,"level":1,"ident":"默认行数","isLeaf":true,"value":"20","modifyTime"
:"2012-03-05T18:00:57"},{"remark":"","no":"","moduleName":"系统参数","_name":"表格","parent":"系统参数","expanded"
:false,"type":"string","section":"表格","id":11,"level":1,"ident":"式样","isLeaf":true,"value":"redmond"
,"modifyTime":"2012-03-05T18:01:33"}],"page":1,"records":2,"rows":10000,"total":1}