Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用于geoJson的jqgrid json读取器_Php_Json_Jqgrid_Geojson_Jsonreader - Fatal编程技术网

Php 用于geoJson的jqgrid json读取器

Php 用于geoJson的jqgrid json读取器,php,json,jqgrid,geojson,jsonreader,Php,Json,Jqgrid,Geojson,Jsonreader,我有一个PHP脚本,可以从数据库中提取有效的GeoJSON数据。现在我想用jqgrid准备这些数据的网格视图,但我无法为javascript代码找到合适的jsonReader 这是我的GeoJSON输出: {"type":"FeatureCollection", "total":0, "page":1, "records":117, "features":[ {"geometry":{"type":"Point","coordinates":[12.3,41.70052]},

我有一个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"
}

有人能帮我写一本实用读物吗?提前感谢

您的主要错误是您试图使用
单元格:“属性”
,但是如果使用
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数据读取到以下网格:


(见演示)。在您的JSON数据中,我仅将
total
值从0更改为1,因为将
total
值减为
page
值毫无意义。

您希望在网格中包含哪些列?
属性
似乎大多不清楚。所有其他条目在数据的
属性部分中是否具有相同的
“specie”
“localita”
“provincia”
属性?仅仅从一个项目就很难理解数据是如何产生的。你能在
“features”
数组中包含更多的项目吗?Thx为了回答这个问题,我在我的JSONY中添加了一些项目,但是你仍然没有写下你需要在网格中包含哪些列。