如何在Extjs存储中为数组使用filterBy方法

时间:2016-03-16 12:53:44

标签: extjs

我使用的是Ext.js 4.1版本。我使用下面的json数据创建了一个dataview(tpl)。我想要的是使用" host"过滤associatedElementsDetails字段。和" policyDetails"

{
    "category": "Hosts Under Maintenance",
    "associatedElementsDetails": [ 
        {
            "host": "windows",
            "policyDetails": [
                {
                    "policyName": "test",
                    "status": "active",
                    "policyTimeLine": [
                        {
                            "date": "Mar 09, 2016-Mar 10, 2016",
                            "time": [
                                {
                                    "timeperiods": "18:41-18:41"
                                },
                                {
                                    "timeperiods": "00:41-18:41"
                                }
                            ]
                        },
                        {
                            "date": "Daily",
                            "time": [
                                {
                                    "timeperiods": "00:00-12:00"
                                }
                            ]
                        }
                    ]
                },
                {
                    "policyName": "test1",
                    "status": "active",
                    "policyTimeLine": [
                        {
                            "date": "Daily",
                            "time": [
                                {
                                    "timeperiods": "00:00-23:59"
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

如何过滤"主机"和" policyTimeLine"使用商店的filterBy方法?

2 个答案:

答案 0 :(得分:0)

你可以使用filterBy(fn,[scope]) 例如:

msgStore.filterBy(function (record){
    if (record.get('host') && record.get('policyDetails')) {
    // do something
        return true;
    }
    return false;

});

答案 1 :(得分:0)

首先,您需要创建商店

Ext.create('Ext.data.Store', {
    autoLoad: true,
    model: 'your model',
    storeId: 'your model id',
    proxy: {
         type: 'ajax',
         url: 'myurl.json',
         reader: {
              type: 'json',
              root: 'people'
         }
    }
});

然后使用商店经理查找

var store = Ext.data.StoreManager.lookup('Your store');
var filter= new Ext.util.Filter({
    filterFn: function(item) {
        //do filter

    }
});

http://existdissolve.com/2011/11/extjs-4-filtering-on-multiple-fields/