如何将简单的 JSON 对象绑定到 jqGrid?
这是我所拥有的:
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>
这会产生错误:
未捕获的语法错误,无法识别的表达式:# inside of jQuery 1.6.2
我也尝试过使用 json 而不是 jsonstring 来替换 datastr。这消除了错误,但网格仍然是空的。在这两种情况下 undefined 都会出现,或者在网格体中闪烁。
编辑
我也尝试过 datatype: "local" 与 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" />