Ext.data.Store getTotalCount()在加载后不计算 [英] Ext.data.Store getTotalCount() doesn't calculate after load

查看:431
本文介绍了Ext.data.Store getTotalCount()在加载后不计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用 getTotalCount()时,我的商店并不总是返回正确的记录数。这个问题发生在我的 load()商店之后。我知道店里有记录在这个检查点。

我正在使用ExtJs 4.1.3

  // this.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: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:{
键入:'json',
root:'data',
totalProperty:'total'
}
},
autoLoad:true
})

我可以确认总额属性是发送对于我的所有请求。

  {
succes:true,
data
// 50记录
],
总:16219,
错误:[]
}


解决方案

加载是异步的。当您打电话时,商店会删除总计数属性,并且在装载后到达两行时,服务器尚未返回尚未更新属性的时间:

  this.grid.getStore()负载(); 

//这两行还没有返回服务器。
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();
}
});


My store doesn't always return the right amount of records when calling getTotalCount(). This problem occurs after I load() the store. I know that there are records in the store at that point of checking.
I am using 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

How can I get the number of records that could be loaded into the Store if the Store contained all data?


My store configuration.

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
            })

I can confirm that the total property is send for all of my requests.

{
    "succes": true,
    "data": [
    //50 records
    ],
    "total": 16219,
    "errors": []
}

解决方案

Load is asynchronous. When you call it, the store deletes the total count property, and by the time you reach the two lines after load most chances the server hasn't returned yet to update the property:

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

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

You should really write:

this.grid.getStore().load({
    scope: this,
    callback: function(records, operation, success) {
        count = this.getCount();
        total = this.getTotalCount();
    }
});

这篇关于Ext.data.Store getTotalCount()在加载后不计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆