我的商店在调用 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/