【发布时间】:2011-06-23 11:16:04
【问题描述】:
我一直在各种论坛上闲逛,并阅读了几个与此问题相关的 stackoverflow 问题,但我终其一生都无法弄清楚出了什么问题。
我尝试使用以下代码生成一个 jqGrid treeGrid:
jQuery("#structureBuilderTable").jqGrid({
url: 'tree.json',
datatype:'json',
mtype:'GET',
colNames: ["ID", "Description", "Total"],
colModel: [
{name:'id', index:'id', width: 1, hidden: true, key: true},
{name:'desc', index:'desc', hidden: false, sortable: true},
{name:'num', index:'num', hidden: false, sortable: true}
],
treeGridModel:'adjacency',
height:'auto',
width:'500',
pager:"#ptreegrid",
treeGrid: true,
ExpandColumn:'desc',
ExpandColClick: true,
caption:"TreeGrid Test"
});
这是我的 .json 文件(作为示例):
{
"total": "1",
"page": "1",
"records": "2",
"rows": [
{"id": "1", "cell": ["1", "Super Item", "300", "0", "null", "false", "false"]},
{"id": "2", "cell": ["2", "Item 1", "100", "1", "1", "false", "false"]},
{"id": "3", "cell": ["3", "Sub Item 1", "50", "2", "2", "true", "true"]},
{"id": "4", "cell": ["4", "Sub Item 2", "25", "2", "2", "false", "false"]},
{"id": "5", "cell": ["5", "Sub-sub Item 1", "25", "3", "4", "true", "true"]},
{"id": "6", "cell": ["6", "Sub Item 3", "25", "2", "2", "true", "true"]},
{"id": "7", "cell": ["7", "Item 2", "200", "1", "1", "false", "false"]},
{"id": "8", "cell": ["8", "Sub Item 1", "100", "2", "7", "false", "false"]},
{"id": "9", "cell": ["9", "Sub-sub Item 1", "50", "3", "8", "true", "true"]},
{"id": "10", "cell": ["10", "Sub-sub Item 2", "50", "3", "8", "true", "true"]},
{"id": "11", "cell": ["11", "Sub Item 2", "100", "2", "7", "true", "true"]}
]
}
(这几乎是我在网上找到的指南的直接副本)。
现在,网格已生成,但它不包含任何数据。 javascript 文件与“tree.json”位于同一目录中,但不知何故似乎找不到它。我将以下内容用于调试目的:
loadError: function(xhr, status, error) {alert(status +error)}
这是我收到的警报:
找不到错误
任何帮助都会非常感激。
【问题讨论】:
-
您是否尝试使用 Firebug 或其他工具进行调试以查看 JSON 是否实际加载正确?好像是找不到JSON。
-
是的,这就是问题所在。我似乎没有找到 .json 文件(可能我对这部分不够清楚)。
-
这很奇怪。我已经用你的选项和你的 JSON 做了一个基本的测试,一切似乎都很好。我不得不注释掉
pager属性,但我怀疑这是你问题的原因。可以在这里找到一个工作示例:minvis.nl/jqGrid/tree.html 也许它对您有用。
标签: javascript jquery json jqgrid treegrid