PDA

View Full Version : Reversed each loop over a store?



Tatonka
27 Aug 2012, 5:02 AM
Hi,

I have a sorted store and would like to loop over said store in the reverse direction. Is there a function/option-to-each to do that?
I would like to avoid resorting the store in the reverse direction since I need to keep the original order for other calculations later.

Thanks
T.

evant
27 Aug 2012, 5:08 AM
var records = store.getRange(),
i = records.length - 1;

while (i--) {
// ...
}

Tatonka
27 Aug 2012, 5:22 AM
Thanks for the answer, I think I'll try something along those lines ..

I thought the getAt() function should be avoided in loops, which is why one should use the each() construct, which is why I asked originally ..

Thanks

evant
27 Aug 2012, 5:24 AM
There's no need to call getAt, records is an array of all the records.

Tatonka
27 Aug 2012, 5:26 AM
argh .. sorry .. getRange() very different from getCount() ..

That, of course, absolutely makes sense ..

T.