ExtJs与JSON格式数据绑定的方法(grid)
2010-03-23 10:37
531 查看
在这个AJAX流行年代,xml绑定已经满足不了我们的需求。ExtJs又为我们提供了JSON格式数据绑定的方法,下面我们来看看效果
用到的有二个文件survey.html、xml-grid.html,注意js引用路径。
survey.html文件:
[{"appeId":"1","survId":"1","location":"","surveyDate":"2008-03-14","surveyTime":"12:19:47","inputUserId":"1","inputTime":"2008-03-14 12:21:51","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"2","survId":"32","location":"","surveyDate":"2008-03-14","surveyTime":"22:43:09","inputUserId":"32","inputTime":"2008-03-14 22:43:37","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"3","survId":"32","location":"","surveyDate":"2008-03-15","surveyTime":"07:59:33","inputUserId":"32","inputTime":"2008-03-15 08:00:44","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"4","survId":"1","location":"","surveyDate":"2008-03-15","surveyTime":"10:45:42","inputUserId":"1","inputTime":"2008-03-15 10:46:04","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"5","survId":"32","location":"","surveyDate":"2008-03-16","surveyTime":"08:04:49","inputUserId":"32","inputTime":"2008-03-16 08:05:26","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"6","survId":"32","location":"","surveyDate":"2008-03-20","surveyTime":"20:19:01","inputUserId":"32","inputTime":"2008-03-20 20:19:32","modifyTime":"0000-00-00 00:00:00"}]
json-grid.html 文件:
<html>
<head>
<link rel="stylesheet" type="text/css"
href="../script/ext/resources/css/ext-all.css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="../script/ext/ext-base.js"></script>
<script type="text/javascript" src="../script/ext/ext-all.js"></script>
<script type="text/javascript"
src="../script/ext/build/locale/ext-lang-zh_CN.js"></script>
<script>
Ext.onReady(function(){
var proxy=new Ext.data.HttpProxy( {url:'survey.html'});
//定义reader
var reader=new Ext.data.JsonReader(
{
},[
{name: 'appeId', mapping: 'appeId'},
{name: 'survId'},
{name: 'location'},
{name: 'surveyDate'},
{name: 'surveyTime'},
{name: 'inputUserId'}
]
)
//构建Store
var store=new Ext.data.Store( {
proxy:proxy,
reader:reader
});
//载入
store.load();
// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: "appeId", width: 60, dataIndex: 'appeId', sortable: true},
{header: "survId", width: 60, dataIndex: 'survId', sortable: true},
{header: "location", width: 60, dataIndex: 'location', sortable: true},
{header: "surveyDate", width: 100, dataIndex: 'surveyDate', sortable: true},
{header: "surveyTime", width: 100, dataIndex: 'surveyTime', sortable: true},
{header: "inputUserId", width:80, dataIndex: 'inputUserId', sortable: true}
],
renderTo:'example-grid',
width:540,
height:200
});
});
</script>
</head>
<body>
<div id="example-grid"></div>
</body>
</html>
用到的有二个文件survey.html、xml-grid.html,注意js引用路径。
survey.html文件:
[{"appeId":"1","survId":"1","location":"","surveyDate":"2008-03-14","surveyTime":"12:19:47","inputUserId":"1","inputTime":"2008-03-14 12:21:51","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"2","survId":"32","location":"","surveyDate":"2008-03-14","surveyTime":"22:43:09","inputUserId":"32","inputTime":"2008-03-14 22:43:37","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"3","survId":"32","location":"","surveyDate":"2008-03-15","surveyTime":"07:59:33","inputUserId":"32","inputTime":"2008-03-15 08:00:44","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"4","survId":"1","location":"","surveyDate":"2008-03-15","surveyTime":"10:45:42","inputUserId":"1","inputTime":"2008-03-15 10:46:04","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"5","survId":"32","location":"","surveyDate":"2008-03-16","surveyTime":"08:04:49","inputUserId":"32","inputTime":"2008-03-16 08:05:26","modifyTime":"0000-00-00 00:00:00"},
{"appeId":"6","survId":"32","location":"","surveyDate":"2008-03-20","surveyTime":"20:19:01","inputUserId":"32","inputTime":"2008-03-20 20:19:32","modifyTime":"0000-00-00 00:00:00"}]
json-grid.html 文件:
<html>
<head>
<link rel="stylesheet" type="text/css"
href="../script/ext/resources/css/ext-all.css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="../script/ext/ext-base.js"></script>
<script type="text/javascript" src="../script/ext/ext-all.js"></script>
<script type="text/javascript"
src="../script/ext/build/locale/ext-lang-zh_CN.js"></script>
<script>
Ext.onReady(function(){
var proxy=new Ext.data.HttpProxy( {url:'survey.html'});
//定义reader
var reader=new Ext.data.JsonReader(
{
},[
{name: 'appeId', mapping: 'appeId'},
{name: 'survId'},
{name: 'location'},
{name: 'surveyDate'},
{name: 'surveyTime'},
{name: 'inputUserId'}
]
)
//构建Store
var store=new Ext.data.Store( {
proxy:proxy,
reader:reader
});
//载入
store.load();
// create the grid
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{header: "appeId", width: 60, dataIndex: 'appeId', sortable: true},
{header: "survId", width: 60, dataIndex: 'survId', sortable: true},
{header: "location", width: 60, dataIndex: 'location', sortable: true},
{header: "surveyDate", width: 100, dataIndex: 'surveyDate', sortable: true},
{header: "surveyTime", width: 100, dataIndex: 'surveyTime', sortable: true},
{header: "inputUserId", width:80, dataIndex: 'inputUserId', sortable: true}
],
renderTo:'example-grid',
width:540,
height:200
});
});
</script>
</head>
<body>
<div id="example-grid"></div>
</body>
</html>
相关文章推荐
- ExtJs与JSON格式数据绑定的方法
- extjs Post方法提交json格式的数据到php
- ExtJs:grid中json的数据绑定(转)
- extjs Post方法提交json格式的数据到php
- Extjs 4.0 Grid 数据绑定 json 分页 不分页
- Struts2与ExtJs Grid结合使用json格式数据
- extjs的grid应用(java 使用json绑定数据 翻页)
- Extjs中grid采用json进行数据绑定的实例
- Extjs Grid 数据绑定 json 分页 不分页
- Python中json格式数据的编码与解码方法详解
- Json数据格式常用处理方法
- jQuery向后台传入json格式数据的方法
- 火车头采集器 8.2 多页采集json格式数据方法
- iOS中解析json格式数据的各种方法调用
- jsp向EXTJS返回json格式数据
- extjs读取解析后端json格式数据并显示条形图
- php里少用到的session_module_name,以及session的key值限制,简单将session存储为json格式数据的方法
- Spring MVC 对于返回JSON格式数据的中文乱码 解决方法
- extjs JSONStore的load事件/insert,add方法应用 如何动态改变显示数据
- 简介Objective-C解析XML与JSON数据格式的方法