用JSON返回数据填充jqGrid并获取Uncaught TypeError无法读取属性'0'的未定义
Populating jqGrid with JSON return data and getting Uncaught TypeError Cannot read property '0' of undefined
我正试图使用Jackson从Spring Web应用程序返回一些JSON,并对其进行解析并将其加载到jqGrid中。
我已经通过JSONViewer扩展将数据返回并在Chrome中可见。在我看来是正确的。
使用arraydata进行的本地测试取得了成功。
这是我的JSP/HTML/JS:
<link rel='stylesheet' type='text/css' href='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/ui-darkness/jquery-ui.css' />
<link rel='stylesheet' type='text/css' href='css/jqGrid/ui.jqgrid.css' />
<script type='text/javascript' src='js/jquery-1.7.1.min.js'></script>
<script type='text/javascript' src='js/jquery-ui-1.8.17.custom.min.js'></script>
<script type='text/javascript' src='js/i18n/grid.locale-en.js'></script>
<script type='text/javascript' src='js/jquery.jqGrid.min.js'></script>
<script type='text/javascript'>
$(document).ready(function () {
jQuery("#list").jqGrid({
url:"formSubmit.html",
datatype: "json",
height: 700,
width: 1100,
colNames: ['ReqID', 'Family', 'ControlID', 'Name', 'Description', 'Category','Priority', 'Notes', 'Parent'],
colModel: [
{ name: 'reqID', index: 'reqID', width: 40 },
{ name: 'family', index: 'family', width: 100 },
{ name: 'controlID', index: 'controlID', width: 100 },
{ name: 'reqName', index: 'reqName', width: 175 },
{ name: 'requirement', index: 'requirement', width: 450,cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'style="white-space: normal;"' } },
{ name: 'category', index: 'category', width: 100 },
{ name: 'priority', index: 'priority', width: 100 },
{ name: 'requirementNotes', index: 'requirementNotes', width: 100 },
{ name: 'parent', index: 'parent', width: 100 }
],
rowNum: 10,
rowList: [10, 20, 30],
pager: '#pager',
viewrecords: true,
jsonReader : { repeatitems: false }
});
jQuery("#list").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false });
});
</script>
<table id = 'list'></table>
以下是使用Jackson从Spring容器返回的一些数据:
{
"total":"1",
"page":"1",
"records":"558",
"rows":[{
"parent":"",
"priority":"",
"requirementNotes":"DummyData",
"category":"DummyData",
"family":"DummyData",
"requirement":"DummyData",
"reqID":"1",
"controlID":"DummyData",
"reqName":"DummyData"}]
}
在jquery.jqGrid.min.js:23中,我一直在返回一个Uncaught TypeError。无法读取未定义中的属性"0"作为我的响应,我被难住了。
从使用您发布的JSON数据和代码的演示中可以看出,jqGrid应该可以正常工作。
我只能重复我在之前的评论中已经写过的内容:参数url:"formSubmit.html"
在我看来非常可疑。如果你调用一些动态组件,你的URL应该没有像"/myurl/"这样的扩展名,或者有像".html"这样的其他扩展名。我建议你分析Fiddler、Firebug或IE或Chrome的开发工具的HTTP流量(查看"网络"选项卡)。重要的不仅可以是HTTP正文,还可以是像"内容类型"这样的HTTP标头。
尝试在jsonreader中设置root: "rows"
。
相关文章:
- TypeError:无法读取属性'推'未定义的JavaScript
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 未捕获的类型错误:无法读取属性'删除'的未定义
- AngularJS指令出错-无法读取属性'编译'的未定义
- 未捕获的类型错误:无法读取属性'name'即使它存在,也无法定义
- 看到“;未捕获的类型错误:无法读取属性'weight'未定义的“;尽管按照字面上的指示
- 无法读取属性'材料'未定义的Three.js
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- Soundcloud Javascript SDK 3.0-回调无法读取属性'connectCallback
- 未捕获的类型错误:无法读取属性'状态'在react中为null
- JavaScript承诺-无法读取属性'那么'的未定义
- Javascript Float32数组抛出无法读取属性'0'即使数组定义良好,也为null
- 未捕获的类型错误:无法读取属性'中止'的未定义
- 角度推入数组给出:TypeError:无法读取属性'推'的未定义
- http/rxjs catch回调中的Angular 2重定向导致TypeError:无法读取属性'订阅'
- Javascript未捕获类型错误:无法读取属性'0'的未定义
- jQuery控制台错误:无法读取属性'top'的未定义
- TypeError:无法读取属性'findAll'的未定义