Sencha touch Sencha Touch根据条件删除存储中的记录

Sencha touch Sencha Touch根据条件删除存储中的记录,sencha-touch,Sencha Touch,我有一个商店,代码如下。我的商店中有7条记录,其中前3条记录的状态为2,其他记录的状态为3。我想删除状态为2的记录。我该怎么走 Ext.define('MyApp.store.MyStore', { extend: 'Ext.data.Store', config: { data: [ [ 1, 'Siesta by the Ocean', '1 Ocean Front, Happy Isl

我有一个商店,代码如下。我的商店中有7条记录,其中前3条记录的状态为2,其他记录的状态为3。我想删除状态为2的记录。我该怎么走

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'
    }
  }
});

必须调用存储的
remove()
方法,传递要删除的记录。因此,调用
each()
方法来迭代存储,检查记录的
状态
,如果它等于2,则将其删除:

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

这样,您只需调用remove一次:

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