我有一个PHP脚本,可以从数据库中提取有效的GeoJSON数据。现在我想用jqgrid准备这些数据的网格视图,但我无法找出javascript代码的正确jsonReader。
这是我的GeoJSON输出:
{"type":"FeatureCollection",
"total":0,
"page":1,
"records":117,
"features":[
{"geometry":{"type":"Point","coordinates":[12.3,41.70052]},
"type":"Feature",
"properties":{
"data":"2006-02-22",
"specie":"S. coeruleoalba",
"localita":"Ostia",
"provincia":"Roma"
},"id":0},
{"geometry":{
"type":"Point","coordinates":[15.26667,40.0502]},
"type":"Feature",
"properties":{
"data":"2006-03-01",
"specie":"S. coeruleoalba",
"localita":"Golfo di Salerno",
"provincia":"Salerno"
},"id":1},
{"geometry":{"type":"Point","coordinates":[14.88333,40.56692]},
"type":"Feature",
"properties":{
"data":"2006-03-03",
"specie":"S. coeruleoalba",
"localita":"Battipaglia",
"provincia":"Salerno"
},"id":2}
]}
使用此阅读器,我的网格显示正确的行数(117)和页面,但空单元格
jsonReader : {
root: "features",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "properties",
id: "id"
}
有人可以帮我写一个有效的读者吗?提前致谢
答案 0 :(得分:0)
您的主要错误是您尝试使用cell: "properties"
,但cell
属性将被忽略,以防repeatitems: false
属性使用。
你应该使用
jsonReader: {
root: "features",
repeatitems: false
}
然后为每列定义jsonmap
属性。例如,您可以使用以下列定义:
colModel: [
{name: 'coordX', jsonmap:'geometry.coordinates.0', width: 75, sorttype: 'number',
formatter: 'number', formatoptions: {decimalPlaces: 5}},
{name: 'coordY', jsonmap:'geometry.coordinates.1', width: 75, sorttype: 'number',
formatter: 'number', formatoptions: {decimalPlaces: 5}},
{name: 'data', jsonmap:'properties.data', width: 90, align: 'center',
sorttype: 'date', datefmt: 'm/d/Y',
formatter: 'date', formatoptions: {newformat: 'm/d/Y'}},
{name: 'specie', jsonmap:'properties.specie', width: 100},
{name: 'localita', jsonmap:'properties.localita', width: 100},
{name: 'provincia', jsonmap:'properties.provincia', width: 80}
]
结果,您将能够将JSON数据读取到以下网格:
(参见演示here)。在您的JSON数据中,我仅将total
值从0更改为1,因为将total
值减少为page
值无意义。