日期:2014-05-16  浏览次数:20678 次

Extjs jsonreader 读到数据, 但是store.getCount()==0
JScript code

var paramsStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url : 'goodparam.ered?method=queryGoodparamList'
        }),    
        reader : new Ext.data.JsonReader({
            totalProperty : 'TOTALCOUNT', // 记录总数
            root : 'ROOT' // Json中的列表数据根节点
        },[
            {
                name: 'id'
            },
            {
                name: 'name'
            }
        ])
    })


paramsStore.load();
页面加载的时候, 后台打印出来
{TOTALCOUNT:3, ROOT:[{"id":"1","name":"cpu"},{"id":"2","name":"硬盘"},{"id":"3","name":"显卡"}]}

alert("有几条数据:"+paramsStore.getCount()); 页面弹出来为0  

明明有3条数据, 不知道为什么 希望各位帮忙解决

------解决方案--------------------
不会extjs。。。

感觉这句应该写在 回调函数里。
alert("有几条数据:"+paramsStore.getCount());


------解决方案--------------------
JScript code

   楼主是在哪alert("有几条数据:"+paramsStore.getCount()); 页面弹出来为0
   你在gridpanel里直接这么写是不行的,你可以在事件中测试或者在grid里的render里测试
   事件测试:
   paramsStore.on('load',function(store, record, opts){
     alert(paramsStore.getCount());
   });
   grid里的列测试:
   {
        header: '状态',
        sortable: true,
        dataIndex: 'STATUS',
        width: 80,
        renderer: (function(v, p, record, rowIndex, index, store){
            alert(store.getCount());
        }).createDelegate(this)
    }

------解决方案--------------------
后台打印出来那句,是否作为响应数据返回前台了?F12看看。
------解决方案--------------------
paramsStore.on("load",function(){
alert("有几条数据:"+paramsStore.getCount()); 
});
得试下很久没用了