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

ExtJS:如何通过过滤隐藏存储上的特定数据?,extjs,filter,load,store,ignore,Extjs,Filter,Load,Store,Ignore,我想在网格中隐藏一条从服务器返回的记录 我在存储上设置了一个过滤器,可以访问特定的数据,但是我将如何处理隐藏/忽略此记录 fooStore: { .... filters: [ function(item) { let me = this; let theRecord = item.data.status === MyApp.STATUS; //true if (theRecord) {

我想在网格中隐藏一条从服务器返回的记录

我在存储上设置了一个
过滤器
,可以访问特定的数据,但是我将如何处理隐藏/忽略此记录

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"
    }
  ]
}

我无法保存我的小提琴,因为我没有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"
    }]
}
我认为它离你的代码很近,在加载存储后,过滤器可以这样工作:

这里是sencha fiddle链接:


如果这不起作用,我不明白他妈的在做什么…

我不能保存我的小提琴,因为我没有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"
    }]
}
我认为它离你的代码很近,在加载存储后,过滤器可以这样工作:

这里是sencha fiddle链接:


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

奇怪。。。您使用的是哪个版本的Extjs?Extjs的版本是
6.5.0
很抱歉,它仍然不能像预期的那样工作,但可能是我造成了一些实现错误。让我检查一下。谢谢你们的努力。所以小提琴就在下面;我只重构了
如果只重构了
部分,并且它按预期工作,但不知何故,当我实现到我的项目中时,仍然加载错误设置的记录,而不是忽略=(@工作得很好。.我在函数方面犯了错误!我在
加载前
中设置了
过滤器
,而不是
加载前
。好吧,我想在
加载前
上声明会更好,但它应该在
加载前
中!非常感谢。奇怪…你使用的是哪个版本的Extjs?Extjs的版本是
6.5.0我很抱歉,但它仍然不能像预期的那样工作,但可能是我犯了一些实现错误。让我检查一下。谢谢你的努力。下面是fiddle;我只重构了
,如果只有
true-false
部分,并且它能像预期的那样工作,但不知何故,当我实现我的项目时,仍然加载了false-setted-record而不是忽略…=(@工作得很好..我在函数方面犯了错误!我在
加载前
中设置了
过滤器,而不是
加载前
。嗯,我想在
加载前
上声明会更好,但它应该在
加载前
中!谢谢。