admin管理员组文章数量:1353578
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 badges1 Answer
Reset to default 8Apparently 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
本文标签: javascriptExtjsBest way to iterate through displayed records in a buffered storeStack Overflow
版权声明:本文标题:javascript - Extjs - Best way to iterate through displayed records in a buffered store - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743935694a2564640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论