问题描述
这是显示部分 var store=new Ext.data.JsonStore({ proxy: new Ext.data.HttpProxy({ url: 'getUserData.jsp' }), //url:'http://design/getUserData.jsp', reader: new Ext.data.JsonReader( {fields:['username','usergroup']} ) /* fields:[ {name:'username'}, {name:'usergroup'}] */ }); store.load(); var gridPanel=new Ext.grid.GridPanel({ store:store, columns:[ /*{ header:'用户ID', dataIndex:'id', width:100 },*/ { header:'用户名', dataIndex:'username', width:160 },{ header:'用户组', dataIndex:'usergroup', width:160 }], viewConfig:{ sortAscText:'正序排列', sortDescText:'逆序排列', forceFit:true }, width:600, height:400, frame:true, //title:'Framed with Checkbox Selection and Horizontal Scrolling', iconCls:'icon-grid' });下面是数据,读取的页面的内容没有html,head和body标签,只有[ {"username":"aaa","usergroup":"bbb"}, {"username":"bbb","usergroup":"111"}]我试过直接在store用data属性直接给值,显示正常,但是一旦到网页去取,就取不到值现在死活拿不到值,试过很多方法了 问题补充:自己后来又试了试,偶然试出来了,JsonReader,HttpProxy好像不用也行,最后,拿到值的代码为 var store=new Ext.data.JsonStore({url:'getUserData.jsp',fields:['id','username','usergroup'] }); store.load();其他都没动,最初试的时候可能将数据页面中的双引号写成了单引号(因为在extjs里,属性的单双引号是通用的,我以为这里也一样,就没注意),可能是这里出的问题吧。
解决方案
JsonStore 里面 与三个属性就足够了 fields url root 后台返回的应该是一个json对象 如果你的root属性为 root:'root' 那么返回的json就应该是 {root:[attr1:value,attr2:value]}fields 是一个数组 里面是属性的名字 具体可以查看api 里面说的很清除
解决方案二:
你的JsonStore中提供了url,缺没有提供method,你写个method=post试试!这可能是ext 的一个bug吧!另外建议你在加点其他的配置属性, autoLoad:false,autoDestroy:true,remoteSort:true,root:'rows',totalProperty:'total',idProperty:'ID',ext就是这样的毛病,有时候少写一个配置,累死都找不出错误