2

I try to remove the duplicate value before storing it into a store. I want to store the same value in the store 1 time only. But it seems the following Ext.Array.unique line does not working. Could anyone please help me to correct this. Thank you

var input1store = new Ext.data.Store({
    fields: [{name: 'name'}],
    proxy: {
        type: 'ajax',
        url: 'www.requesturl.com?format=json&source1',
        reader: {
            type: 'json',
            root: 'xml.result'
        }
    },
    autoLoad: false,
    sorters: [{property: 'name', direction: 'asc'}],
    listeners:{
        load: function(rec){
            uniqueArray = Ext.Array.unique(rec.getRange());
        }
    }
});
4

2 回答 2

5

您可以使用该filterBy方法过滤掉加载后不想出现在商店中的记录。

clearFilter请注意,商店将保留过滤出的记录的副本,如果被调用(可能是您或使用商店的组件),它将恢复。如果您想彻底删除这些记录,则必须删除该副本。

Ext.create('Ext.data.Store', {
    fields: ['name'],

    // example data
    proxy: {
        type: 'memory',
        data: [{name: 'Foo'},{name:'Bar'},{a:'Baz'},{a:'Foo'},{a:'Bar'}],
    },

    listeners: {
        load: function(store) {
            // using a map of already used names
            const hits = {}
            store.filterBy(record => {
                const name = record.get('name')
                if (hits[name]) {
                    return false
                } else {
                    hits[name] = true
                    return true
                }
            })

            // delete the filtered out records
            delete store.snapshot
        },
    },
})
于 2013-06-05T19:24:45.907 回答
1

您可以在商店http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model-cfg-idPropertyidProperty中指定值 (idProperty == 'name') 。

于 2013-06-07T20:57:38.570 回答