本地讀取數(shù)據(jù)
Ext.onReady(function(){
var data=[ [1, 'EasyJWeb', 'EasyJF','www.easyjf.com'],
[2, 'jfox', 'huihoo','www.huihoo.org'],
[3, 'jdon', 'jdon','www.jdon.com'],
[4, 'springside', 'springside','www.springside.org.cn'] ];
var store=new Ext.data.SimpleStore({data:data,fields:["id","name","organization","homepage"]});
var grid = new Ext.grid.GridPanel({
renderTo:"hello",
title:"中國(guó)Java開(kāi)源產(chǎn)品及團(tuán)隊(duì)",
height:150,
width:600,
columns:[{header:"項(xiàng)目名稱",dataIndex:"name"},
{header:"開(kāi)發(fā)團(tuán)隊(duì)",dataIndex:"organization"},
{header:"網(wǎng)址",dataIndex:"homepage"}],
store:store,
autoExpandColumn:2
});
});
與服務(wù)器端交換(服務(wù)器端用servlet來(lái)處理讀取和更新數(shù)據(jù))
var store=new Ext.data.JsonStore({
url:"student.ejf?cmd=list",
root:"result",
fields:["id","name","email","bornDate"]});
得到的數(shù)據(jù)格式為:{results:[{id:1,
name:'小王',
email:'xiaowang@easyjf.com',
sex:'男',
bornDate:'1991-4-4'},
{id:1,
name:'小李',
email:'xiaoli@easyjf.com',
sex:'男',
bornDate:'1992-5-6'}
]
}
Store可以理解為數(shù)據(jù)存儲(chǔ)器,可以理解為客戶端的小型數(shù)據(jù)表,提供緩存等功能。在ExtJS中,GridPanel、ComboBox、DataView等控件一般直接與Store打交道,直接通過(guò)store來(lái)獲得控件中需要展現(xiàn)的數(shù)據(jù)等
讀數(shù)據(jù)時(shí)
record是指數(shù)據(jù)讀取的格式
store 有幾種讀取數(shù)據(jù)的方法:
1,就是上面這種最簡(jiǎn)單的
2,將數(shù)據(jù)表示為一維數(shù)組的格式,然后用Ext.data.JsonStore來(lái)存貯
var data=[{id:1,
name:'EasyJWeb',
organization:'EasyJF',
homepage:'www.easyjf.com'},
{id:2,
name:'jfox',
organization:'huihoo',
homepage:'www.huihoo.org'}
];
var store=new Ext.data.JsonStore({data:data,fields:["id","name","organization","homepage"]});
3,將數(shù)據(jù)表示為xml文件,再讀取:
hello.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<row> <id>1</id> <name>EasyJWeb</name> <organization>EasyJF</organization> <homepage>www.easyjf.com</homepage> </row>
<row> <id>2</id> <name>jfox</name> <organization>huihoo</organization> <homepage>www.huihoo.org</homepage> </row>
</dataset>
讀取程序:
var store=new Ext.data.Store({
url:"hello.xml",
reader:new Ext.data.XmlReader({
record:"row"},
["id","name","organization","homepage"])
});
4,向服務(wù)器端讀取數(shù)據(jù)的時(shí)候,與3極為類似:
var store=new Ext.data.Store({
url:"student.ejf?cmd=list",
reader:new Ext.data.JsonReader({
root:"result"},
["id","name","organization","homepage"])
});
看看是不是和3中的讀取程序相像,當(dāng)然它還有進(jìn)一步的簡(jiǎn)化:
var store=new Ext.data.JsonStore({
url:"student.ejf?cmd=list",
root:"result",
fields:["id","name","organization","homepage"]});
服務(wù)器端產(chǎn)生的數(shù)據(jù)輸出是:
{results:[{id:1,
name:'小王',
email:'xiaowang@easyjf.com',
sex:'男',
bornDate:'1991-4-4'},
{id:2,
name:'小李',
email:'xiaoli@easyjf.com',
sex:'男',
bornDate:'1992-5-6'}
]
}
5,向服務(wù)器發(fā)送數(shù)據(jù)
function sFn()
{
alert('保存成功');
}
function fFn()
{
alert('保存失敗');
}
Ext.Ajax.request({
url: 'student.ejf?cmd=save’
success: sFn
failure: fFn,
params: { name: '小李',email: ' xiaoli@easyjf.com',bornDate: ' 1992-5-6',sex: '男'}
});
posted on 2008-07-10 10:02
開(kāi)機(jī) 閱讀(409)
評(píng)論(0) 編輯 收藏 所屬分類:
js