2011-10-28 41 views
0

我有一個PHP腳本從數據庫中提取有效的GeoJSON數據。現在我想用jqgrid準備這些數據的網格視圖,但是我無法弄清楚JavaScript代碼的正確的jsonReader。jqgrid json geoJson reader

這是我的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

你想在網格中有什麼列? 「物業」似乎大多不清楚。所有其他條目在數據的「屬性」部分中具有相同的「specie」,「localita」和「provincia」屬性?僅僅從一個項目就很難理解數據是如何的。你可以在''features「''數組中包含更多項目嗎? – Oleg

+0

Thx爲答案,我添加了一些項目給我的Json – user781065

+0

你仍然沒有寫出你需要在網格中有哪些列。 – Oleg

回答

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數據下面的網格:

enter image description here

(見演示here)。在您的JSON數據中,我只將total的值從0更改爲1,因爲它沒有意義將total的值減去page的值。

+0

@ user781065:不客氣! – Oleg