代码之家  ›  专栏  ›  技术社区  ›  Nuri Engin

extjs:如何通过过滤隐藏存储中的特定数据?

  •  0
  • Nuri Engin  · 技术社区  · 6 年前

    我想隐藏网格上从服务器返回的记录。

    我设置了一个 filter 存储并可以访问特定数据,但如何处理隐藏/忽略此记录?

    fooStore: {
        ....
        filters: [
             function(item) {
             let me = this;
             let theRecord = item.data.status === MyApp.STATUS; //true
    
             if (theRecord) {
                  console.log(theRecord); //True
                  console.log("So filter is here!!")
                  //How to hide/ignore/avoid to load this specific data record to load Grid??
                }
             }
        ]
    },
    

    返回JSON;

    {
      "success": true,
      "msg": "OK",
      "count": 3,
      "data": [
        { 
          //Filter achives to this record and aim to hide this one; avoid to load this record.
          "id": 102913410,
          "status": "P"
        },
        {
          "id": 98713410,
          "status": "I"
        },
        { 
          "id": 563423410,
          "status": "A"
        }
      ]
    }
    
    1 回复  |  直到 6 年前
        1
  •  4
  •   Enzo B.    6 年前

    我无法保存我的小提琴,因为我没有Sencha Forum的帐户,所以我给你我的代码:

    Ext.application({
        name : 'Fiddle',
    
        launch : function() {
            var model = Ext.create('Ext.data.Model', {
                extend: 'Ext.data.Model',
                fields: [
                    {name: 'id',  type: 'int'},
                    {name: 'status', type: 'string'},
                ]
            });
    
            var store = Ext.create('Ext.data.Store', {
                 autoLoad: true,
                 model: model,
                 proxy: {
                    type: 'ajax',
                    url:  'data.json',
                    reader: {
                        type: 'json',
                        rootProperty: 'data'
                    }
                },
                filters: [function(item) {
                    if (item.data.status === "P") {
                        return true;
                    }
                    else {
                        return false;
                    }
                }],
                listeners: {
                    load: {
                        fn: function() {
                            console.log(this.getRange());
                        }
                    }
                }
            });
        }
    });
    

    我还创建了data.json,如下所示:

    {
        "success": true,
        "msg": "OK",
        "count": 3,
        "data": [{
            "id": 102913410,
            "status": "P"
        }, {
            "id": 98713410,
            "status": "I"
        }, {
            "id": 563423410,
            "status": "A"
        }]
    }
    

    我认为它离你的代码很近,在商店加载之后,过滤器就可以工作了,你可以这样做:

    enter image description here

    这里是sencha-fiddle链接: https://fiddle.sencha.com/#view/editor

    如果这样不行,我不明白他妈的在干什么……