3

调用时,我的商店并不总是返回正确数量的记录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": []
}
4

1 回答 1

8

Load是异步的。当您调用它时,商店会删除总计数属性,并且当您在加载后到达两行时,服务器可能还没有返回更新属性:

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();
    }
});
于 2013-03-07T12:43:01.573 回答