代码之家  ›  专栏  ›  技术社区  ›  SharpCoder

Ext.data.Store的each()正在忽略筛选的记录

  •  6
  • SharpCoder  · 技术社区  · 11 年前

    我正在使用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.properties=something更新该记录中的某个属性)时,该记录没有得到更新。

    谢谢

    5 回复  |  直到 11 年前
        1
  •  12
  •   kuldarim    8 年前

    使用这个

    var allRecords = store.snapshot || store.data;
    

    然后像这样循环

    allRecords.each(function(record) {
        console.log(record);
    });
    

    看看这个 store snapshot

        2
  •  5
  •   AnthonyVO    11 年前

    在Sencha Touch 2.3上,我需要做以下操作来绕过过滤器。

    var allRecords = store.queryBy(function(){return true;});
    
    allRecords.each(function(r){
        doStuff();
    });
    
        3
  •  3
  •   Benjamin E.    9 年前

    从Extjs 5开始使用以下内容

    Ext.data.Store.each( fn, [scope], [includeOptions] )
    

    store.each(function(record) {
        // ...
    }, scope, {filtered: true});
    
        4
  •  2
  •   Snehal Masne    10 年前
    //  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);  
    
        5
  •  0
  •   Chirag Bhatt    6 年前

    您可以使用getStore().getDataSource().each(函数(r){});获取所有数据甚至存储的函数