0
votes

I have a store with following code. I have 7 records in my store in which first 3 record are having a status 2 and others have the status 3. I want to delete the records whose status is 2. How do I go about

Ext.define('MyApp.store.MyStore', {
  extend: 'Ext.data.Store',

  config: {
    data: [
        [
            1,
            'Siesta by the Ocean',
            '1 Ocean Front, Happy Island',
            1
        ],
        [
            2,
            'Gulfwind',
            '25 Ocean Front, Happy Island',
            1
        ],
        [
            3,
            'South Pole View',
            '1 Southernmost Point, Antarctica',
            1
        ],
        [
            4,
            'ABC',
            '11 Address1',
            2
        ],
        [
            5,
            'DEF',
            '12 Address2',
            2
        ],
        [
            6,
            'GHI',
            '13 Address3',
            2
        ],
        [
            7,
            'JKL',
            '14 Address4',
            2
        ]
    ],
    storeId: 'MyStore',
    fields: [
        {
            name: 'id',
            type: 'int'
        },
        {
            name: 'name',
            type: 'string'
        },
        {
            name: 'address',
            type: 'string'
        },
        {
            name: 'status',
            type: 'int'
        }
    ],
    proxy: {
        type: 'localstorage'
    }
  }
});
2

2 Answers

2
votes

You have to call the remove() method of the store, passing the record you want to remove. So, call the each() method to iterate through the store, check the status of the record and remove that if it is equal to 2:

Ext.getStore('MyStore').each(function(record) {
    if (record.get('status') === 2) {
        Ext.getStore('MyStore').remove(record);
    }
}, this);
0
votes

This way you only call remove once:

var store = Ext.getStore('MyStore');
var records2del = [];
store.each(function(record) {
    if (record.data.status == 2) {
        records2del.push(record);
    }
}, this);
store.remove(records2del);