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

qzlgjiam  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(173)

我想隐藏从服务器返回的Grid上的记录。
我已经在存储上设置了一个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"
    }
  ]
}
r7knjye2

r7knjye21#

我不能保存我的小提琴,因为我没有 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 小提琴链接:https://fiddle.sencha.com/#view/editor
如果这不起作用,我不明白他妈的在干什么...

相关问题