【问题标题】:ExtJS: How to hide specific data on store with filtering?ExtJS:如何通过过滤隐藏存储中的特定数据?
【发布时间】:2018-12-27 16:21:35
【问题描述】:

我想在 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"
    }
  ]
}

【问题讨论】:

    标签: filter extjs load store


    【解决方案1】:

    我无法保存我的小提琴,因为我没有 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"
        }]
    }
    

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

    这里是煎茶小提琴链接:https://fiddle.sencha.com/#view/editor

    如果这行不通,我不明白他妈的在做什么......

    【讨论】:

    • 奇怪...你用的是哪个版本的Extjs?
    • ExtJS 的版本是6.5.0
    • 我很抱歉,但它仍然没有按预期工作,但也许我犯了一些实施错误。让我检查一下。感谢您的努力。
    • 下面是小提琴;我只重构了if onlytrue false 部分,它按预期工作,但不知何故,当我实施到我的项目时,仍然加载错误的设置记录而不是忽略... =(@fiddle.sencha.com/#view/editor&fiddle/2jj5
    • 完美运行..我在功能上犯了错误!我在beforeload 中设置了filters,而不是load。好吧,我认为在beforeload 上声明会更好,但它应该在load 中!非常感谢。
    猜你喜欢
    • 2015-03-25
    • 1970-01-01
    • 2022-06-15
    • 2011-11-02
    • 1970-01-01
    • 2018-03-31
    • 2020-09-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多