Jquery JqGrid未显示任何数据
我已经写了这段代码Jquery JqGrid未显示任何数据,jquery,jqgrid,Jquery,Jqgrid,我已经写了这段代码 <html> <head> <title>My First JqGrid</title> <script src="js/jquery-1.8.2.min.js"></script> <link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.7.2.custom.css"
<html>
<head>
<title>My First JqGrid</title>
<script src="js/jquery-1.8.2.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.7.2.custom.css" />
<script src="js/jquery.jqGrid.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<script type="text/javascript">
$(document).ready(function(){
var obj;
var mydata='[{"id":"1"},{"id":"2"}]';
obj = JSON.parse(mydata);
$("#list").jqGrid({
dataType: 'json',
data :obj,
colNames: ['id'],
colModel: [
{ name: 'id', index: 'id', width: 120, sortable: true }
],
autowidth: true,
viewrecords: true
});
});
</script>
</head>
<body>
<table id="list">
<tr>
<td></td>
</tr>
</table>
</body>
我的第一个JqGrid
$(文档).ready(函数(){
var-obj;
var mydata='[{“id”:“1”},{“id”:“2”}];
obj=JSON.parse(mydata);
$(“#列表”).jqGrid({
数据类型:“json”,
资料来源:obj,
colNames:['id'],
colModel:[
{name:'id',index:'id',宽度:120,可排序:true}
],
自动宽度:正确,
viewrecords:正确
});
});
一切正常。但是我看不到数据。可能是什么问题
提前感谢。如果您正在使用本地数据(如上面所述的本地数组),则需要将
数据类型
选项更改为本地
。另外,请记住,这些内容是区分大小写的,因此在您的案例中,您有数据类型
,而实际上,它是数据类型
datatype: 'local'
另外,由于您使用的是本地数据(数组),所以只需将数组传递给jQGrid即可,不需要像上面那样将数组解析为JSON
从jQGrid文档:
数据:
存储传递到网格的本地数据的数组。如果要加载数组数据,可以直接指向此变量。
数据类型
定义填充网格的数据的格式。有效的选项有xml(我们期望xml格式的数据)、xmlstring(我们期望xml数据为字符串)、json(我们期望json格式的数据)、jsonstring(我们期望json数据为字符串)、local(我们期望客户端定义的数据(数组数据))