这几天在学习EXT,从网上打到一位兄弟写的PHP+EXT的实例,但我在使用Ext.data.JsonStore来填充GridPanel时总时返回记录为空,但数据库里是有值的,而且服务器端输出的JsonStore也是有值的,代码如下:
------------------------------------------------
Ext.onReady(function() {
var store=new Ext.data.JsonStore({
id:"Id",
url: 'user.php?cmd=List',//默认的数据源地址,继承时需要提供
root: "rows",
totalProperty:"totalCount",
remoteSort:true,
fields:["Id","Name","Password","Email","Re"]
});
store.on('load',function(tempstore){alert(tempstore.getCount())});
store.load({params:{start:0, limit:20}});
});
----------------------------------------------------
服务器端JsonStore输出:{'totalCount':'7','rows':[{'Id':'1','Name':'name1','Password':'1234','Email':' [email protected] [email protected] ','Re':'ss'},{'Id':'2','Name':'name2','Password':'name2','Email':' [email protected] [email protected] ','Re':'ss'},{'Id':'3','Name':'kevin','Password':'zhao','Email':'[email protected]','Re':'Test'},{'Id':'4','Name':'zzj','Password':'zzj','Email':'zzj','Re':'zzj'},{'Id':'5','Name':'a','Password':'b','Email':'d','Re':'d'},{'Id':'6','Name':'e','Password':'e','Email':'e','Re':'e'},{'Id':'7','Name':'a','Password':'b','Email':'c','Re':'d'}]}
-----------------------------------------------------
在GridPannel里是这样下的: initComponent : function(){
this.name=new Ext.form.TextField({
name: 'name',
anchor:'95%',
maxLength:25
});
this.store=new Ext.data.JsonStore({
id:"Id",
url: 'user.php?cmd=List',//默认的数据源地址,继承时需要提供
root: "rows",
totalProperty:"totalCount",
remoteSort:true,
autoLoad: true,
fields:["Id","Name","Password","Email","Re"],
});
this.cm.defaultSortable=true;
this.sm= new Ext.grid.CheckboxSelectionModel();
Mis.Ext.CrudPanel.superclass.initComponent.call(this);
var viewConfig=Ext.apply({forceFit:true},this.gridViewConfig);
this.grid=new Ext.grid.GridPanel({
store: this.store,
cm: this.cm,
sm:this.sm,
trackMouseOver:false,
loadMask: true,
viewConfig:viewConfig,
tbar: [{
id:'addButton',
text: '新增',
iconCls:'addIconCss',
tooltip:'添加新纪录',
handler: this.create,
scope:this
},'-',//'-'给工具栏按钮之间添加'|'
{
id:'editButton',
text:'编辑',
iconCls:'editIconCss',
tooltip:'修改记录',
handler: this.edit,
scope:this
},'-',
{
text:'删除',
iconCls:'deleteIconCss',
tooltip:'删除所选中的信息',
handler: this.removeData,
scope:this
},'-',
{
text:'刷新',
iconCls:'refreshIcon',
tooltip:'刷新纪录',
handler: this.refresh,
scope:this
},'->',//'->'代表让工具栏按钮到右边去
'用户名: ',this.name,
{
text: '查询',
pressed: true,
iconCls:'selectIconCss',
handler: this.search,
scope:this
},' '
],
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: this.store,
displayInfo: true,
displayMsg: '显示第 {0} - {1} 条记录,共 {2}条记录',
emptyMsg: "没有记录"
})
});
//双击时执行修改
this.grid.on("celldblclick",this.edit,this);
this.add(this.grid);
this.store.load({params:{start:0,limit:10}});
}
-------------------------------------
测试网址:http://csrlaws.intertekchina.com:81/phpext/Json数据服务网址:http://csrlaws.intertekchina.com:81/phpext/user.php?cmd=List
------------------------------------------------
Ext.onReady(function() {
var store=new Ext.data.JsonStore({
id:"Id",
url: 'user.php?cmd=List',//默认的数据源地址,继承时需要提供
root: "rows",
totalProperty:"totalCount",
remoteSort:true,
fields:["Id","Name","Password","Email","Re"]
});
store.on('load',function(tempstore){alert(tempstore.getCount())});
store.load({params:{start:0, limit:20}});
});
----------------------------------------------------
服务器端JsonStore输出:{'totalCount':'7','rows':[{'Id':'1','Name':'name1','Password':'1234','Email':' [email protected] [email protected] ','Re':'ss'},{'Id':'2','Name':'name2','Password':'name2','Email':' [email protected] [email protected] ','Re':'ss'},{'Id':'3','Name':'kevin','Password':'zhao','Email':'[email protected]','Re':'Test'},{'Id':'4','Name':'zzj','Password':'zzj','Email':'zzj','Re':'zzj'},{'Id':'5','Name':'a','Password':'b','Email':'d','Re':'d'},{'Id':'6','Name':'e','Password':'e','Email':'e','Re':'e'},{'Id':'7','Name':'a','Password':'b','Email':'c','Re':'d'}]}
-----------------------------------------------------
在GridPannel里是这样下的: initComponent : function(){
this.name=new Ext.form.TextField({
name: 'name',
anchor:'95%',
maxLength:25
});
this.store=new Ext.data.JsonStore({
id:"Id",
url: 'user.php?cmd=List',//默认的数据源地址,继承时需要提供
root: "rows",
totalProperty:"totalCount",
remoteSort:true,
autoLoad: true,
fields:["Id","Name","Password","Email","Re"],
});
this.cm.defaultSortable=true;
this.sm= new Ext.grid.CheckboxSelectionModel();
Mis.Ext.CrudPanel.superclass.initComponent.call(this);
var viewConfig=Ext.apply({forceFit:true},this.gridViewConfig);
this.grid=new Ext.grid.GridPanel({
store: this.store,
cm: this.cm,
sm:this.sm,
trackMouseOver:false,
loadMask: true,
viewConfig:viewConfig,
tbar: [{
id:'addButton',
text: '新增',
iconCls:'addIconCss',
tooltip:'添加新纪录',
handler: this.create,
scope:this
},'-',//'-'给工具栏按钮之间添加'|'
{
id:'editButton',
text:'编辑',
iconCls:'editIconCss',
tooltip:'修改记录',
handler: this.edit,
scope:this
},'-',
{
text:'删除',
iconCls:'deleteIconCss',
tooltip:'删除所选中的信息',
handler: this.removeData,
scope:this
},'-',
{
text:'刷新',
iconCls:'refreshIcon',
tooltip:'刷新纪录',
handler: this.refresh,
scope:this
},'->',//'->'代表让工具栏按钮到右边去
'用户名: ',this.name,
{
text: '查询',
pressed: true,
iconCls:'selectIconCss',
handler: this.search,
scope:this
},' '
],
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: this.store,
displayInfo: true,
displayMsg: '显示第 {0} - {1} 条记录,共 {2}条记录',
emptyMsg: "没有记录"
})
});
//双击时执行修改
this.grid.on("celldblclick",this.edit,this);
this.add(this.grid);
this.store.load({params:{start:0,limit:10}});
}
-------------------------------------
测试网址:http://csrlaws.intertekchina.com:81/phpext/Json数据服务网址:http://csrlaws.intertekchina.com:81/phpext/user.php?cmd=List
解决方案 »
- ext4的dockedItems有什么用?
- 求一个JQuery TreeView最简单的例子
- js怎么实现 提交 超链接
- 急求一段类似百度空间中的相册效果代码!!
- 用JS+XML+HTML做的随机测试生成,可是试题显示不出来,实在找不到错误,憋死我了
- 关于document中的select元素展开的问题
- o = document.getElementsByName("aa")是得到一个数组,那么怎样清除这个数组的所有元素?
- 如何通过js进行表单提交
- 急:用控件播放rm文件只有声音没有图像,请问是怎么回事?
- 用js怎么控制submit类型按钮的提交?详情见内!急用阿~~~
- 谁能实现类似这样的功能图?
- getElementById在IE中正常在Firefox不起作用
sd
'sd
sd'},{'Id':'5','Name':'a','Password':'b','Email':'d','Re':'d'},{'Id':'6','Name':'adfadsf','Password':'123456','Email':'[email protected]','Re':'asdf'},{'Id':'7','Name':'a','Password':'b','Email':'c','Re':'d'}]}数据似乎不太对吧
'skdjksd;
sd
'sd
sd'}你查查这里,
然后再查看是否是grid的问题。
对返回的 json 数据不要有换行,对换成进行转移, 要练成一串 JSON 字符串。