如何在 Sencha Touch 应用程序中使用以前的过滤器获取总记录?
how to get total records with a previous filter in a Sencha Touch app?
在使用基于 Sencha Touch 的应用程序时,我需要获取商店的总量,但需要实现先前的过滤器。
我可以 store.getCount()
并知道一家商店的总记录数,但是如何使用先前的过滤器知道总记录数?
这是一个替代解决方案:
var count = 0;
store.findBy(function(rec) {
if (rec.get('myFilter')) {
count++; // Only counting matching data
}
});
console.log(count); // Total amount of filtered data
发件人:https://www.sencha.com/forum/showthread.php?174156-Store-count-by-criteria-without-filter
如果商店被过滤 getCount()
将根据您的过滤器检索记录量。如果您过滤 'Billy',如果有 2 个 'Billy's'.
,getCount()
将 return 只有 2 个
来自文档:
Gets the number of records in store.
If using paging, this may not be the total size of the dataset. If the
data object used by the Reader contains the dataset size, then the
Ext.data.ProxyStore.getTotalCount function returns the dataset size.
Note: see the Important note in Ext.data.ProxyStore.load.
When store is filtered, it's the number of records matching the
filter.
如果你想获得记录的总数,你可以使用getTotalCount()
。这将计算所有记录,无论是否过滤。
来自文档:
Returns the total number of Model instances that the Proxy indicates
exist. This will usually differ from getCount when using paging -
getCount returns the number of records loaded into the Store at the
moment, getTotalCount returns the number of records that could be
loaded into the Store if the Store contained all data
如果您想查询整个商店,您可以对集合使用 queryBy
. This will return a collection of records. You can then use getCount()
。
var billies = store.queryBy(function(rec, id) {
return rec.get('name') === 'billy';
});
billies.getCount();
在使用基于 Sencha Touch 的应用程序时,我需要获取商店的总量,但需要实现先前的过滤器。
我可以 store.getCount()
并知道一家商店的总记录数,但是如何使用先前的过滤器知道总记录数?
这是一个替代解决方案:
var count = 0;
store.findBy(function(rec) {
if (rec.get('myFilter')) {
count++; // Only counting matching data
}
});
console.log(count); // Total amount of filtered data
发件人:https://www.sencha.com/forum/showthread.php?174156-Store-count-by-criteria-without-filter
如果商店被过滤 getCount()
将根据您的过滤器检索记录量。如果您过滤 'Billy',如果有 2 个 'Billy's'.
getCount()
将 return 只有 2 个
来自文档:
Gets the number of records in store.
If using paging, this may not be the total size of the dataset. If the data object used by the Reader contains the dataset size, then the Ext.data.ProxyStore.getTotalCount function returns the dataset size. Note: see the Important note in Ext.data.ProxyStore.load.
When store is filtered, it's the number of records matching the filter.
如果你想获得记录的总数,你可以使用getTotalCount()
。这将计算所有记录,无论是否过滤。
来自文档:
Returns the total number of Model instances that the Proxy indicates exist. This will usually differ from getCount when using paging - getCount returns the number of records loaded into the Store at the moment, getTotalCount returns the number of records that could be loaded into the Store if the Store contained all data
如果您想查询整个商店,您可以对集合使用 queryBy
. This will return a collection of records. You can then use getCount()
。
var billies = store.queryBy(function(rec, id) {
return rec.get('name') === 'billy';
});
billies.getCount();