Javascript 使用JSON数据时,jqGrid初始化为空
我一直潜伏在各种论坛上,读了一些与这个问题相关的问题,但我一辈子都搞不清楚到底出了什么问题 我尝试使用以下代码生成jqGrid treeGrid:Javascript 使用JSON数据时,jqGrid初始化为空,javascript,jquery,json,jqgrid,treegrid,Javascript,Jquery,Json,Jqgrid,Treegrid,我一直潜伏在各种论坛上,读了一些与这个问题相关的问题,但我一辈子都搞不清楚到底出了什么问题 我尝试使用以下代码生成jqGrid treeGrid: jQuery("#structureBuilderTable").jqGrid({ url: 'tree.json', datatype:'json', mtype:'GET', colNames: ["ID", "Description", "Total"],
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”位于同一目录中,但不知何故它似乎找不到它。我使用以下方法进行调试:
{
"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"]}
]
}
loadError:functionxhr,状态,错误{alertstatus+error}
这是我收到的警报:
找不到错误
非常感谢您的任何帮助。我希望基于JSON数据和jqGrid创建的代码能够帮助您找到代码中的错误。可能您只是忘了将创建网格的代码放在jQueryfunction{/**};中
只有一个提示:如果您希望某个树节点像我的演示中那样展开显示,那么您不仅要在最后一列展开的隐藏列中设置真值,还要为树网格的隐藏加载列添加真值。有关更多详细信息,请参阅和。是否尝试使用Firebug或其他工具进行调试,以查看JSON是否正确加载?看起来找不到的是JSON。是的,这就是问题所在。我似乎找不到.json文件,也许这部分我不够清楚。这很奇怪。我已经用你的选项和JSON做了一个基本测试,一切似乎都很好。虽然我不得不注释掉寻呼机属性,但我怀疑这是你问题的原因。在这里可以找到一个有效的例子:也许它对你们有些用处。非常感谢你们两位的帮助!:-原来是项目配置的外部错误导致了该错误。我会好好利用你的两个演示!