我正在使用Ext.data.Store的each()。但是,此方法在筛选存储时仅循环筛选的记录。我们是否有任何其他方法或解决方法来循环访问商店的所有记录,即使在商店上应用了过滤器。
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();
});
该行实际上var allRecords = attStore.snapshot || attStore.data;
按预期返回所有记录,但是当我尝试更新该记录(或使用 record.data.property = 某些内容更新该记录中的某个属性)时,该记录没有更新。
谢谢
使用这个
var allRecords = store.snapshot || store.data;
并像这样循环
allRecords.each(function(record) {
console.log(record);
});
查看此商店快照
在Sencha Touch 2.3上,我需要执行以下操作来绕过过滤器。
var allRecords = store.queryBy(function(){return true;});
allRecords.each(function(r){
doStuff();
});
从 Extjs 5 开始,使用以下
Ext.data.Store.each( fn, [scope], [includeOptions] )
即
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);
您可以使用getStore().getDataSource().each(function (r) {}); 函数获取所有数据甚至存储