2012-03-06 84 views

回答

0

您有奇怪的問題和所有關於jsonReader。在當前情況下,您可以使用

jsonReader: { 
    root: 'features', 
    repeatitems: false 
} 

來讀取數據。 The demo展示瞭如何結果可能是這樣的:

enter image description here

修訂:我怎麼知道,你要真正做的是調用一些外部 URL它提供你回JSON。由於安全原因,無法將標準Ajax請求發送到其他服務器(請參閱same origin policy)。幸運的是,服務器sampleserver1.arcgisonline.com/ArcGIS支持JSONP請求。因此,以填補與外部數據網格,你可以使用下面的代碼

$('#grid').jqGrid({ 
    url: 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/4/query', 
    datatype: 'jsonp', 
    postData: $.param({ 
     where: "1=1", 
     returnGeometry: false, 
     outFields: "ObjectID,NAME,STATE_NAME,CNTY_FIPS", 
     f: "json" 
    }), 
    colModel: [ 
     {name: 'ObjectID', label: 'ID', width: 60, jsonmap: 'attributes.ObjectID'}, 
     {name: 'NAME', label: 'Name', width: 150, jsonmap: 'attributes.NAME'}, 
     {name: 'STATE_NAME', label: 'State', width: 120, jsonmap: 'attributes.STATE_NAME'}, 
     {name: 'CNTY_FIPS', label: 'FIPS', width: 60, jsonmap: 'attributes.CNTY_FIPS'} 
    ], 
    toppager: true, 
    jsonReader: { 
     root: 'features', 
     repeatitems: false 
    }, 
    loadonce: true, 
    ignoreCase: true, 
    height: 'auto' 
}); 

看到新的演示here

UPDATED 2:爲了能夠使用本地搜索/過濾,應該修改上面的代碼。這是更好地更換postData其中一個上面看到下面的參數

ajaxGridOptions: { cache: true }, 
prmNames: {search: null, nd: null, sort: null, rows: null, order: null, page: null}, 
postData: { 
    where: "1=1", 
    returnGeometry: false, 
    outFields: "ObjectID,NAME,STATE_NAME,CNTY_FIPS", 
    f: "json" 
} 

the corresponding demo其中filterToolbar作品。

+0

謝謝奧列格。 我的工作是關於地理信息系統和網絡開發,其中一個重要部分是在網格中呈現地理空間數據,所以我認爲我的問題並不奇怪......可能我必須閱讀更精確的json閱讀器文檔。再次感謝您 – user781065 2012-03-06 21:32:06

+0

@ user781065:不客氣!我忘了提及,我在答案中額外使用了'jsonmap',就像'jsonmap:'attributes.NAME''。您可以在[這裏]找到官方文檔(http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data)。關於[jsonReader as function](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function),實際上可以讀取任何JSON輸入。另外有時使用'beforeProcessing'回調會有幫助。如果問題解決了,您可以將答案標記爲「已接受」。 – Oleg 2012-03-06 21:44:52

+0

奧列格,你嘗試過我在第一篇文章中提供的網址嗎? 使用它的網格總是空的,螢火蟲返回狀態200確定的請求,但在紅色... – user781065 2012-03-07 10:56:04