EXT 获取数据问题

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个回答

var statusStore = new Ext.data.JsonStore({
            autoLoad:true,
            url : "getContractStatusExt.do",
            fields : [{
                        name : 'value'
                    }, {
                        name : 'display'
                    }],
            listeners:{
                load:function(){
                    status.setValue(statusStore.getAt(1).get('value'));
                }
            }
        });

//store的加载,后台返回:[{"display":"请选择","value":""},{"display":"正常","value":"0"},{"display":"失效","value":"1"}]

var status = new Ext.form.ComboBox({
            store : statusStore,
            emptyText : '请选择',
            fieldLabel : '状态',

            triggerAction : 'all',
            hiddenName : 'status',
            valueField : 'value',
            displayField : "display",
            readOnly : true,
                            width : 100
        });

stcCallback1001是什么东东

root: 'results',
totalProperty: 'total',

要对应
{"total":1,
"totalProperty":[{"tid":1,"tname":"tom","tpass":"tompass"}]}

呃,看错,

要在监听里面查询

personnelStore.on('load',function(){
personnelStore.getAt(0));

});
personnelStore.load();

我从来没用过那个
用:new Ext.data.JsonStore({
url : url,
autoLoad : autoLoad,
fields : [{
name : 'value'
}, {
name : 'display'
}]
})

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问