easyui中datagrid执行loadData方法出现异常

在测试easyui中datagrid加载本地文件时,使用 loadData方法出现异常。

loadData使用的时候,提示:Cannot read property 'options' of undefined

具体如下:

jquery.easyui.min.js:10372 Uncaught TypeError: Cannot read property 'options' of undefined
    at _718 (jquery.easyui.min.js:10372)
    at HTMLTableElement.<anonymous> (jquery.easyui.min.js:11312)
    at Function.each (jquery.min.js:2)
    at n.fn.init.each (jquery.min.js:2)
    at Object.loadData (jquery.easyui.min.js:11311)
    at n.fn.init.$.fn.datagrid (jquery.easyui.min.js:11073)
    at 表格过滤 - 副本.html:47

有人说是格式的问题。需要JSON对象,而不能是JSON格式的字符串。但没有解决。

我的测试代码如下:

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Basic DataGrid - jQuery EasyUI Demo</title>
	<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../demo.css">
</head>
<body>
	<h2>Basic DataGrid</h2>
	<div style="margin:20px 0;"></div>
	
	<table id="dg" class="easyui-datagrid" title="Basic DataGrid" style="width:700px;height:250px"
			data-options="singleSelect:true,collapsible:true" >
		<thead>
			<tr>
				<th data-options="field:'itemid',width:80">Item ID</th>
				<th data-options="field:'productid',width:100">Product</th>
				<th data-options="field:'listprice',width:80,align:'right'">List Price</th>
				<th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
				<th data-options="field:'attr1',width:250">Attribute</th>
				<th data-options="field:'status',width:60,align:'center'">Status</th>
			</tr>
		</thead>
	</table>

	<script type="text/javascript" src="../jquery.min.js"></script>
	<script type="text/javascript" src="../jquery.easyui.min.js"></script>
	<script type="text/javascript">
		var data ={"total":28,"rows":[
			{"productid":"FI-SW-01","productname":"Koi","unitcost":10.00,"status":"P","listprice":36.50,"attr1":"Large","itemid":"EST-1"},
			{"productid":"K9-DL-01","productname":"Dalmation","unitcost":12.00,"status":"P","listprice":18.50,"attr1":"Spotted Adult Female","itemid":"EST-10"}
			]};
		
		$('#dg').datagrid('loadData', data); 

	</script>
</body>
</html>

后来 发现有人说是html的加载顺序有关系。所有怀疑还没加载好table这个标签,就执行了$('#dg').datagrid('loadData', data); 

所有就修改为

    $(document).ready(
            function (){
                $('#dg').datagrid("loadData",data);
            }
        );

就可以啦!记录一下。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值