What is the best way to delete multiple entries from a store? Extjs

What is the best way to delete multiple conditional entries in extjs?

For example:

var store = Ext.create('Ext.data.Store', {
    data: [
        {name: 'Ed', age: 21},
        {name: 'Tommy', age: 15},
        {name: 'Aaron', age: 18},
        {name: 'John', age: 22}
    ]
});

I want to delete entries whose age is less than 20 (In this case, “Tommy” and “Aaron”). This question may be the same as finding several entries that are largely a condition.

+4
source share
4 answers

API , , , , - :

var subCollection = store.getData().createFiltered(function(item){
    return item.get('age') < 20;
});

store.remove(subCollection.getRange());
+5

, removeAll, ,

for ( var i = store.data.length; i--; ) {
    if ( store.data[i].age > 20 ) store.removeAt(i);
}
+2
store.remove(
    store.queryBy(function(record) {
        ...
    }).getRange()
)

works at 4, 5 and 6.

+1
source

Another approach:

// get records..

        records.forEach(function (record) {
            if (record.getData().age < 20) {
                store.remove(record);
            }
        });
0
source

Source: https://habr.com/ru/post/1623573/


All Articles