这几天在学习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

解决方案 »

  1.   

    测试网址:http://csrlaws.intertekchina.com:81/phpext/ 打开什么都没有.
      

  2.   

    {'totalCount':'4','rows':[{'Id':'8','Name':'hello','Password':'hello','Email':'[email protected]','Re':'skdjksd; 
    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'}你查查这里,
      

  3.   

    除了数据的问题,再查下是否有汉语的,"':等等,还有文件本身编码是否为utf-8(我是用.net的,php用什么不太清楚,你改改试试)
      

  4.   

    先在JsonStore的onload事件中查看一下客户端是否已经获得数据了
    然后再查看是否是grid的问题。
      

  5.   


      对返回的 json 数据不要有换行,对换成进行转移, 要练成一串 JSON 字符串。