Extjs is the best way to iterate over displayed records in buffered storage

So, I am upgrading from EXT 4.1.1a to 4.2.2 and am facing a problem with buffered storages. In 4.1.1a I could use store.eachto iterate over the currently displayed store records, but in 4.2.2 I just get the error:

TypeError: Cannot read property 'length' of undefined

Basically, inside a store object, a property datano longer has a property items, and the method eachuses the property lengthfor items, therefore, an error. Instead, the items in the store appear to be in data.map. I could go through data.map, but there seems to be a better way. The docs mention only store.each as a way to do this, although this does not seem to work for buffered stores.

I repeat through storage on a listener refreshattached to a grid view.

Any help with this would be greatly appreciated

+4
source share
1 answer

Apparently, they think that you cannot sort out the store because it has “rare” data, but it is not. You can currently do the following.

if(store.buffered) {
    // forEach is private and part of the private PageMap
    store.data.forEach(function(record, recordIdx) {
        /* Do stuff with the record here */
    }, this);
} else {
    store.each(function(record) {
        /* Do the same stuff I guess */
    }, this);
}

IMPORTANT

Take care that the structure of the store may change in the future, which will probably slow down your code.

In addition, I firmly believe that if the right design patterns were used, I eachhad to take care of the cycle without worrying about the structure.

OPTIMIZATION

What I usually do when I initialize the repository is the following:

if(store.buffered) {
    store.iterate = store.data.forEach;
} else {
    store.iterate = store.each;
}

:

store.iterate(fn, scope);

, if-

+7

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


All Articles