如何將簡單的JSON對象綁定到jqGrid?將jqGrid綁定到JSON對象
這是我有:
var tableSrc = { "page":"1", "total":1, "records":"3", "rows": [
{ "title": "Title1", "subtitle": "subTitle", "authors": ["a1", "a2", "a3"] },
{ "title": "Title2", "subtitle": "subtitle", "authors": ["X", "Y"] },
{ "title": "Title3", "subtitle": "subTitle", "authors": ["1", "2", "3", "4"]}]
};
$(".jqGridTarget").jqGrid({
datastr: tableSrc,
datatype: "jsonstring",
colNames: ['title', 'subtitle'],
colModel: [
{ name: 'title', index: 'title', width: 55 },
{ name: 'subtitle', index: 'subtitle', width: 90}]
});
然後:
<table class="jqGridTarget">
</table>
這產生了錯誤:
Uncaught Syntax error, unrecognized expression: # inside of jQuery 1.6.2
我使用JSON而不是與數據jsonstring也嘗試替換數據。這消除了錯誤,但網格仍然是空的。在兩種情況下都會出現undefined,或者在網格體中閃爍。
編輯
我也試過數據類型: 「本地」 與tableSrc數據。沒有錯誤或未定義,但網格中仍然沒有數據。
編輯完
而且,這裏是我所引用的腳本/ css文件:
<script type='text/javascript' src='jquery.min.js'></script>
<script type='text/javascript' src='jquery.tmpl.js'></script>
<script type='text/javascript' src='jquery.jqGrid.min.js'></script>
<script type='text/javascript' src='knockout-1.2.1.js'></script>
<link rel="Stylesheet" type="text/css" href="ui.jqgrid.css" />
[沒有這樣的東西作爲JSON對象。](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) –
我知道,我知道。這就是大多數人所稱的,所以我想我會把它稱爲... –