2012-06-04 85 views
0

我是extjs的新手,并且正在根据Ext.data.store()中的记录数创建动态屏幕。 getTotalCount/getCount用于从商店获取记录的数量。我需要的总记录没有保存在一个变种,并将其返回商店中没有记录没有返回extjs

我试图做这样的事情

function Get_count() 
{ 
    var num;        
    CacheStore.on({ 

      'load':{ 

      fn : function(store,records,options){ 
        num = getTotalCount(); 
        //console.info('Store count = ', tsize); 
        //console.info(' count = ', getCount()); 
      }, 
      scope: this 
    }, 
    'loadexception' : { 
      fn : function (obj,options,response,e){ 
        //console.info('error = ', e); 
      }, 
    scope : this 
    } 

}); 

    // this is a wrong logic but have to do something similar 
    //return num; //return num 

    }; 
    tsize = Get_count(); 

我总是在TSIZE空。我也尝试getCount()而不是getTotalCount(),但我得到同样的问题。

不知道我在哪里出错

回答

1

你的逻辑有点戳在这里。您无法触发将监听器添加到存储完成加载时挂钩的存储的功能。 (你可以,但是这是一个微妙的错误)。

你需要做的是在包含你想使用的号码的功能,当你创建它的商店,声明的监听器。

cacheStore =Ext.create... 
cacheStore.on('load',function(store,records,e){ 
    //dosomestuff that needs the count 
    var num= store.totalCount() 
    //now you use the num in here, else you create an async error 

    //or you can ... 
    my.someFunc(num); 
    //in here, but you can only run it after the store has loaded 
},this); 
+0

嗨亚历克斯我试图用,但我得到的错误“null为空或不是对象” –