extjs 3.4.0 - 如何过滤读取 JSON 的商店

extjs 3.4.0 - How to filter store that reads JSON

我正在尝试筛选 privilege 字段的值为 32 的 JSON。我尝试了多种过滤方法,但它仍然返回所有行而不是过滤后的行。

Ext.onReady(function () {        

        // create the data store
        var store = new Ext.data.Store({
            url: url,
            reader: new Ext.data.JsonReader({
                root: 'keys',
                idProperty: 'key',
                fields: ['key', 'name']
            }),
            autoLoad: true
        });

        store.filter({
            property: 'privileges',
            value: 32,
            type: 'int',
            exactMatch: true
        });

        //create the Grid
        var grid = new Ext.grid.GridPanel({
            store: store,
            columns: [
                {
                    id       :'name',
                    header   : 'Name', 
                    width    : 500, 
                    sortable : true, 
                    dataIndex: 'name'
                },
                {
                    header   : 'Key', 
                    width    : 500, 
                    sortable : false, 
                    dataIndex: 'key'
                },
                {
                    header   : 'Regenerate', 
                    width    : 300, 
                    dataIndex: ''
                }
            ],
            stripeRows: true,
            height: 350,
            title: 'Administrator Keys'
        });

        grid.render('restApiKeyContent');
    });

目前我的JSON如下

{
"id": "abc123",
"name": "Test",
"queue": "test",
"expire": "2118-11-27T02:05:15.546778Z",
"keys": [
    {
        "key": "64654asdsad1sd1",
        "customer": "Test Customer",
        "externalUser": "123213",
        "name": "Jenna Testing API Key 1",
        "privileges": 31
    },
    {
        "key": "7c5362f98f084ae7b76b8484f660fdcf",
        "customer": "Test Customer",
        "externalUser": "123213",
        "name": "Jenna Testing API Key 1",
        "privileges": 16
    }
}

感谢是否有人可以指导我如何通过以 Keys 作为根的特定字段过滤 JSON?

这可能对您有所帮助。在 store 加载后在 JSONReader 中添加 privileges 字段并过滤 store:

Ext.onReady(function () {        

        // create the data store
        var store = new Ext.data.Store({
            url: 'filter-store-extjs3.json',
            reader: new Ext.data.JsonReader({
                root: 'keys',
                idProperty: 'key',
                fields: ['key', 'name', 'privileges']
            }),
            autoLoad: true,
            listeners: {
                load: function() {
                    store.filter('privileges', '16', true, true);
                }
            }
        });

        var grid = new Ext.grid.GridPanel({
            renderTo: Ext.getBody(),
            store: store,
            columns: [
                {
                    id       :'name',
                    header   : 'Name', 
                    width    : 500, 
                    sortable : true, 
                    dataIndex: 'name'
                },
                {
                    header   : 'Key', 
                    width    : 500, 
                    sortable : false, 
                    dataIndex: 'key'
                },
                {
                    header   : 'Regenerate', 
                    width    : 300, 
                    dataIndex: ''
                }
            ],
            stripeRows: true,
            height: 350,
            title: 'Administrator Keys'
        });
});