ext json数据的读取

huangdh12 2010-01-16 09:49:39


Ext.onReady(function(){
var data={
totalcount:10,
root:[
{name:'name1',id:'id1',sex:'sex1'},
{name:'name2',id:'id2',sex:'sex2'},
{name:'name3',id:'id3',sex:'sex3'},
{name:'name4',id:'id4',sex:'sex4'},
{name:'name5',id:'id5',sex:'sex5'},
{name:'name6',id:'id6',sex:'sex6'},
{name:'name7',id:'id7',sex:'sex7'},
{name:'name8',id:'id8',sex:'sex8'},
{name:'name9',id:'id9',sex:'sex9'},
{name:'name10',id:'id10',sex:'sex10'}
]
};
var reader = new Ext.data.JsonReader(
{root:'root'},[
{name:'name'},
{name:'id'},
{name:'sex'}
]
);

var proxy = new Ext.data.MemoryProxy(data);

var store = new Ext.data.Store({
proxy: proxy,
reader:reader
});

var cm = new Ext.grid.ColumnModel([
{header:'名字',dataIndex:'name'},
{header:'id号',dataIndex:'id'},
{header:'性别',dataIndex:'sex'},
]);

var grid = new Ext.grid.GridPanel({
store:store,
cm:cm,
autoHeight : true
});
grid.render('hello');
});



为何我这样数据读取不了?
json数据应该用什么proxy?
...全文
98 2 打赏 收藏 举报
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
huangdh12 2010-01-17
  • 打赏
  • 举报
回复
奥。。。忘了load数据。
谢谢:)
hookee 2010-01-16
  • 打赏
  • 举报
回复

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script>
Ext.onReady(function(){
var data={
totalcount:10,
root:[
{name:'name1',id:'id1',sex:'sex1'},
{name:'name2',id:'id2',sex:'sex2'},
{name:'name3',id:'id3',sex:'sex3'},
{name:'name4',id:'id4',sex:'sex4'},
{name:'name5',id:'id5',sex:'sex5'},
{name:'name6',id:'id6',sex:'sex6'},
{name:'name7',id:'id7',sex:'sex7'},
{name:'name8',id:'id8',sex:'sex8'},
{name:'name9',id:'id9',sex:'sex9'},
{name:'name10',id:'id10',sex:'sex10'}
]
};
var reader = new Ext.data.JsonReader(
{root:'root'},[
{name:'name'},
{name:'id'},
{name:'sex'}
]
);

var proxy = new Ext.data.MemoryProxy(data);
var store = new Ext.data.Store({
proxy: proxy,
reader:reader
});
store.load();
var cm = new Ext.grid.ColumnModel([
{header:'名字',dataIndex:'name'},
{header:'id号',dataIndex:'id'},
{header:'性别',dataIndex:'sex'}
]);
var grid = new Ext.grid.GridPanel({
store:store,
cm:cm,
autoHeight : true
});
grid.render('hello');

});
</script>
<div id="hello"></div>
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2010-01-16 09:49
社区公告
暂无公告