use this
var allRecords = store.snapshot || store.data;
and loop like this
allRecords.each(function(record) {
console.log(record);
});
see this store snapshot
题
I am using Ext.data.Store's each(). But this method, when store is filtered, only loops over the filtered records. Do we have any other method or work around to loop over all the records of a store even when a filter is applied on the store.
var attStore = Ext.getStore("myStore");
var allRecords = attStore.snapshot || attStore.data;
allRecords.each(function (record) {
if (record.data.IsUpdated) {
record.set('updatedByUser', true);
}
else {
record.set('updatedByUser', false);
}
record.commit();
});
The line var allRecords = attStore.snapshot || attStore.data;
actually returns all the records as intended but when I try to update that record (or one of the property in that record using record.data.property = something) That record is not getting updated.
Thanks
解决方案
use this
var allRecords = store.snapshot || store.data;
and loop like this
allRecords.each(function(record) {
console.log(record);
});
see this store snapshot
其他提示
On Sencha Touch 2.3 I needed to do the following to bypass the filter.
var allRecords = store.queryBy(function(){return true;});
allRecords.each(function(r){
doStuff();
});
Starting from Extjs 5 use the following
Ext.data.Store.each( fn, [scope], [includeOptions] )
i.e.
store.each(function(record) {
// ...
}, scope, {filtered: true});
// Here's how you can do that ...
myStore.each(function(record)
{
record.fields.each(function(field)
{
var fieldValue = record.get(field.name);
});
// Alternatively...
/*
for (var rd in record.data)
{
var fName = rd;
var fValue = record.data[rd];
}
*/
}, this);
You can use getStore().getDataSource().each(function (r) {}); function to get all data even store