【问题标题】:no of records in a store are not returning in extjs商店中的记录没有在 extjs 中返回
【发布时间】:2012-06-05 23:08:32
【问题描述】:

我是 extjs 的新手,正在根据 Ext.data.store(); 中的记录数创建一个动态屏幕; getTotalCount/getCount 用于从存储中获取记录数。我需要将总记录数存储在 var 中并返回

我正在尝试做这样的事情

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() 但我遇到了同样的问题。

不知道哪里出错了

【问题讨论】:

    标签: extjs global-variables local-variables


    【解决方案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);
    

    【讨论】:

    • 嗨,alex,我尝试使用它,但我收到错误“null is null or not an object”
    猜你喜欢
    • 2020-03-02
    • 2012-12-21
    • 2017-02-24
    • 2011-12-24
    • 2014-01-21
    • 2013-11-20
    • 2017-09-05
    • 1970-01-01
    • 2013-02-03
    相关资源
    最近更新 更多