A1r*_*Pun 3 extjs store extjs4
我的商店在打电话时并不总是返回正确数量的记录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
Run Code Online (Sandbox Code Playgroud)
如果商店包含所有数据,我如何获得可以加载到商店的记录数量?
我的商店配置.
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
})
Run Code Online (Sandbox Code Playgroud)
我可以确认该total属性是针对我的所有请求发送的.
{
"succes": true,
"data": [
//50 records
],
"total": 16219,
"errors": []
}
Run Code Online (Sandbox Code Playgroud)
Load是异步的.当你调用它时,商店会删除总计数属性,当你加载最多几次机会后到达两行时,服务器还没有返回更新属性:
this.grid.getStore().load();
// Server hasn't returned yet for these two lines.
count = this.grid.getStore().getCount();
total = this.grid.getStore().getTotalCount();
Run Code Online (Sandbox Code Playgroud)
你应该写:
this.grid.getStore().load({
scope: this,
callback: function(records, operation, success) {
count = this.getCount();
total = this.getTotalCount();
}
});
Run Code Online (Sandbox Code Playgroud)