extjs - 加载后不计算 Ext.data.Store getTotalCount()

标签 extjs extjs4 store

我的商店在调用 getTotalCount() 时并不总是返回正确数量的记录.我load()之后出现这个问题商店。我知道在那个检查点商店里有记录。
我正在使用 ExtJs 4.1.3

//this.grid = reference to my grid
var count = this.grid.getStore().getCount(), //50
    total = this.grid.getStore().getTotalCount(); //16000

    this.grid.getStore().load();

    count = this.grid.getStore().getCount(); //50
    total = this.grid.getStore().getTotalCount(); //0

如果 Store 包含所有数据,我如何获得可以加载到 Store 中的记录数?

我的商店配置。
store: Ext.create('Ext.data.Store', {
                model: me.modelName,
                remoteSort: true,
                remoteFilter: true,
                pageSize: 50,
                trailingBufferZone: 25,
                leadingBufferZone: 50,
                buffered: true,
                proxy: {
                    type: 'ajax',
                    actionMethods: { read: 'POST' },
                    api: {
                        read: me.urls.gridUrl
                    },
                    extraParams: Ext.applyIf({ FilterType: 0 }, me.urlParams.gridUrlParams),
                    simpleSortMode: true,
                    reader: {
                        type: 'json',
                        root: 'data',
                        totalProperty: 'total'
                    }
                },
                autoLoad: true
            })

我可以确认total属性是针对我的所有请求发送的。
{
    "succes": true,
    "data": [
    //50 records
    ],
    "total": 16219,
    "errors": []
}

最佳答案

Load是异步的。当您调用它时,存储会删除 total count 属性,并且当您在加载后到达两行时,服务器尚未返回更新属性的可能性最大:

this.grid.getStore().load();

// Server hasn't returned yet for these two lines.
count = this.grid.getStore().getCount();
total = this.grid.getStore().getTotalCount();

你真的应该写:
this.grid.getStore().load({
    scope: this,
    callback: function(records, operation, success) {
        count = this.getCount();
        total = this.getTotalCount();
    }
});

关于extjs - 加载后不计算 Ext.data.Store getTotalCount(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15266605/

相关文章:

javascript - 无法获取未定义或空引用的属性 'id'

javascript - 不带正文的 HTTP DELETE 请求

php - 在 YII 中使用 ExtJS

c# - 如何将密码存储在数据库表中

google-app-engine - Google App Engine 和键值存储

javascript - 发布到服务器时如何处理extjs 4的动态加载?

events - ext js 中是否有任何列单击事件?

recursion - ExtJS中递归扩展树节点

javascript - 在 Ext.Panel 中的元素之间添加边距

java - 如何在 Java 或 AS3 中创建和旋转三维矩阵