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

时间:2018-07-19 13:39:23

标签: extjs filter load store ignore

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

我已经在商店中设置了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 个答案:

答案 0 :(得分:4)

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

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小提琴链接:https://fiddle.sencha.com/#view/editor

如果这行不通,我不知道该死在做什么...