Easyui datagrid加载本地Json数据,CGI数据
网上示例(记得引用Jquery):
- var jsonstr = '{"total":1,"rows":[{"id":"M000005","name":"检测设备","sortid":3,"valid":"1","handler":"系统管理员"}]}';
- var data = $.parseJSON(jsonstr);
- $('#goods_Type_Grid').datagrid('loadData', data); //将数据绑定到datagrid
自己修改后的实例:
<script type="text/javascript">
$(document).ready(function(){
fLoadTable();
fLoadData();
})
function fLoadTable(){
$('#tt').datagrid({
title: '用户列表',
width: 700,
height: 300,
fitColumns: true,
columns:[[
{field:'strUserName',title:'用户名',width:80},
{field:'strUserPwd',title:'密码',width:120}
]]
});
};
function fLoadData(){
$.ajax({
type:"GET",
url:"cgi-bin/postUserDatatoHTML.cgi",
success:function (data){
var vData = $.parseJSON(data);
$('#tt').datagrid('loadData', vData); //将数据绑定到datagrid
}
});
}
</script>
</head>
<body>
<div id="sdfjas" style="float:left; margin-top:10px; height:auto; width:800px;">
<table id="tt">
</table>
</div>
</body>
</html>