将JSON数据映射到jqGrid

编程入门 行业动态 更新时间:2024-10-27 19:27:48
本文介绍了将JSON数据映射到jqGrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下面的代码创建一个javascript对象,将其转换为JSON,然后尝试将其加载到jqGrid中.我一直在跟踪Wiki示例,但我觉得我已经非常精确地遵循了它们的指导,但是仍然没有运气.谁能看到这里缺少的链接?

the below code creates a javascript object, converts it to JSON, and attempts to load it into a jqGrid. I have been following the wiki examples, and I feel I have followed their lead very precisely, but still am having no luck. Can anyone see what the missing link is here?

jQuery(document).ready(function () { var gridData = { total: 2, page: '1', records: '12', rows: [ { id: '1', col1: 'cell11', col2: 'cell12', col3: 'cell13' }, { id: '2', col1: 'cell21', col2: 'cell22', col3: 'cell23' } ] }; gridData = $.toJSON(gridData); $('#jqgrid').jqGrid({ data: gridData, datatype: 'json', colNames: ['Col1', 'Col2', 'Col3'], colModel: [ { name: 'col1' }, { name: 'col2' }, { name: 'col3' } ], jsonReader: { root: 'rows', total: 'total', page: 'page', records: 'records', repeatitems: false, id: '0' } })

推荐答案

您不需要将数据转换为JSON字符串. jqGrid将不得不将数据转换回去.在这种情况下,您应该使用datatype:'jsonstring'和datastr:gridData.

You don't need convert the data to JSON string. jqGrid will have to convert the data back. In the case you should use datatype:'jsonstring' and datastr:gridData.

最好的方法是只使用项目数组:

The best way would be to use just array of item:

var gridData = [ { id: '1', col1: 'cell11', col2: 'cell12', col3: 'cell13' }, { id: '2', col1: 'cell21', col2: 'cell22', col3: 'cell23' } ]; $('#jqgrid').jqGrid({ data: gridData, datatype: 'local', ... });

更多推荐

将JSON数据映射到jqGrid

本文发布于:2023-10-28 02:01:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   JSON   jqGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!