2013-03-07 45 views
3

當調用getTotalCount()時,我的商店並不總是返回適量的記錄。在我店load()之後發生此問題。我知道在那個檢查點有商店裏的記錄。
我使用ExtJS的4.1.3Ext.data.Store getTotalCount()在加載後不會計算

//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: 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": [] 
} 
+1

請提供商店配置和服務器數據 - 您是否忘記發送「總計」值? – sunsay 2013-03-07 10:15:57

+1

是的,我很確定你忘了第二次發送完整的道具,或者有一個錯誤。 – sra 2013-03-07 10:21:27

+0

我已更新包含商店配置的帖子。服務器數據無關緊要。 – A1rPun 2013-03-07 10:23:24

回答

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(); 
    } 
}); 
+0

這工作:)仍然不明白爲什麼'getCount()'返回正確的值。 – A1rPun 2013-03-07 13:00:56

+3

我假設它返回之前的值,它在加載時不會被刪除。 – Izhaki 2013-03-07 13:11:23