最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extjs - Best way to iterate through displayed records in a buffered store - Stack Overflow

programmeradmin2浏览0评论

So, I'm upgrading from EXT 4.1.1a to 4.2.2 and have e across a problem with buffered stores. In 4.1.1a I could use store.each to iterate through the currently displayed store records, but in 4.2.2 I simply get the error:

TypeError: Cannot read property 'length' of undefined

Basically inside the store object the data property does not have an items property anymore, and the each method uses the length property of the items, hence the error. Instead the items in the store seem to reside in data.map. I could loop through data.map but it seems there should be a better way. The docs only mention store.each as the way to do this even though this seems to fail for buffered stores.

I'm iterating through the store on the refresh listener attached to the grids view.

Any help with this would be much appreciated

So, I'm upgrading from EXT 4.1.1a to 4.2.2 and have e across a problem with buffered stores. In 4.1.1a I could use store.each to iterate through the currently displayed store records, but in 4.2.2 I simply get the error:

TypeError: Cannot read property 'length' of undefined

Basically inside the store object the data property does not have an items property anymore, and the each method uses the length property of the items, hence the error. Instead the items in the store seem to reside in data.map. I could loop through data.map but it seems there should be a better way. The docs only mention store.each as the way to do this even though this seems to fail for buffered stores.

I'm iterating through the store on the refresh listener attached to the grids view.

Any help with this would be much appreciated

Share Improve this question asked May 15, 2014 at 1:55 Coin_opCoin_op 10.7k4 gold badges37 silver badges47 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Apparently they think you can't iterate over the store because it has "sparse" data, but that is not true. Currently, what you could do is 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 can change the structure of the store in the future which will surely brake your code.

Additionally, I strongly believe that if proper design patterns were used, each had to take care of the looping without caring about the structure.

OPTIMIZATION

What I usually do, when I initialize the store is the following:

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

Then you could just use it like this:

store.iterate(fn, scope);

This is not the best decision but simplifies writing a lot of if-statements

发布评论

评论列表(0)

  1. 暂无评论