0
好吧,所以我試圖用jqgrid加載一些簡單的json數據到一個html表中。我已經看到一些使用jsonreader選項提到的帖子,但我無法找到如何正確實施它的文檔。我以爲這會超級簡單! anywahy頁面是 http://thethunderdome.hfbsite.com/economy/test.htm試圖加載簡單的json到jQGrid
JS代碼:
$(function(){
var pricesUrl = "/economy/prices3.txt"
jQuery("#pricetable").jqGrid({
url:pricesUrl,
datatype: "json",
colNames:['Item Name','Price', 'Trade Status'],
colModel:[
{name:'Name', width:100},
{name:'Price', width:90},
{name:'Trade',width:100},
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'Name',
viewrecords: true,
sortorder: "asc",
caption:"JSON Example"
});
});
JSON數據:
[
{
"Price":"5",
"Name":"Wood",
"Trade":"all"
},
{
"Price":"5",
"Name":"Sulfur Ore",
"Trade":"all"
},
{
"Price":"5",
"Name":"Raw Chicken Breast",
"Trade":"all"
},
{
"Price":"5",
"Name":"Cloth",
"Trade":"all"
},
{
"Price":"5",
"Name":"Metal Ore",
"Trade":"all"
},
{
"Price":"5",
"Name":"Stones",
"Trade":"all"
},
{
"Price":"5",
"Name":"Animal Fat",
"Trade":"all"
},
{
"Price":"12500",
"Name":"M4",
"Trade":"all"
},
"Price":"9000",
"Name":"Shotgun",
"Trade":"all"
},
"Price":"500",
"Name":"Small Medkit",
"Trade":"all"
},
}
"Price":"1000",
"Name":"Large Medkit",
"Trade":"all"
},
]
arghhh!它非常明顯!謝謝! –
@DanielWard:不客氣!此外,我會建議你在所有的jqGrid中包含'loadError'回調。它可以節省你很多時間。有關更多詳細信息,請參見[答案](http://stackoverflow.com/a/6969114/315935)。 – Oleg