zjwit
zjwit
2010-05-18 10:58

EXT 获取数据问题

  • ext
  • javascript

action 代码

String callback=request.getParameter("callback");
TestDAO tsDao=new TestDAO();
int id=1; //是数据库中记录的ID

List querylist=tsDao.query(id);
JsonConfig jConfig=new JsonConfig();

jConfig.registerJsonValueProcessor(java.util.Date.class,new DateJsonValueProcessor("yyyy-MM-dd"));
StringBuilder strbuilder=new StringBuilder();
if(callback!=null)
strbuilder.append(callback);//.append("({")

     strbuilder.append("({\"total\":").append(querylist.size()).append(",\"results\":"); 

JSONArray jsonArray=JSONArray.fromObject(querylist,jConfig);
strbuilder.append(jsonArray).append("})");

String jsonString=strbuilder.toString();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/xml");//EXT为srciptTagproxy时 类型必须为text/xml
response.getWriter().write(jsonString);

ext代码

var s=new Ext.data.Record.create( [
{name: 'tid', mapping: 'tid'},
{name: 'tname', mapping: 'tname'},
{name: 'tpass', mapping: 'tpass'}
]);

var personnelStore = new Ext.data.Store({
    proxy: new Ext.data.ScriptTagProxy({ url : 'te.jsp'}),//ScriptTag
   reader: new Ext.data.JsonReader({
        root: 'results',
        totalProperty: 'total',
        id:'tid'
    },s),

remoteSort: false
});

personnelStore.load();   

alert(personnelStore.getAt(0)); 此句提示未定义

控制台的数据信息

stcCallback1001({"total":1,"results":[{"tid":1,"tname":"tom","tpass":"tompass"}]})

问题 personnelStore.load(); script error 报错
无法获取到json的数据,请大家看看我这代码有问题吗

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答