-
11 Oct 2012 6:14 AM #1
Answered: load store on painted event
Answered: load store on painted event
Hi all,
i have a carousel that has a onPainted event binded, in which i load a store with photos and add them in the carousel. The thing is that the photos are actually shown in the carousel after the second time the carousel gets painted. Why this is happening?
My code:
thank youCode:onFashionCarouselPainted{ storePhotos.load(); fashionCarousel = Ext.getCmp('FashionCarousel'); fashionCarousel.removeAll(); storePhotos.each(function(record){ fashionCarousel.add({ html: '<h1>' + record.get('title') + '<h1/>' }); }); fashionCarousel.setActiveItem(0); }
-
Best Answer Posted by Schildi
Hi spirosdi,
ah, I looked at your code again and saw another possible error cause.
Probably the problem of the "delay" is, that your store is simply not loaded at this point of time (ajax is asynchronous).
You call, but direclty after that, you want to go through the records with Ext.each(...).Code:storePhotos.load();
What you probably need is the callback functionality of store load, so that you don't loop through the records before the store is loaded.
Try this:
Hope that it does the trick ;-)Code:onFashionCarouselPainted{ storePhotos.load({ callback: function(records, operation, success) { fashionCarousel = Ext.getCmp('FashionCarousel'); fashionCarousel.removeAll(); Ext.each(records, function(current) { fashionCarousel.add({ html: '<h1>' + current.get('title') + '<h1/>' }); }); fashionCarousel.setActiveItem(0); }, scope: this }); }
Best regards,
Schildi
-
11 Oct 2012 6:40 AM #2
Hi spirosdi,
did you try to use a different event? I could imagine that initialize is more what you're looking for.
What I also saw is that there's something special about the painted event in carousels. In the docs it sais
(see http://docs.sencha.com/touch/2-0/#!/...-event-painted)Note: This event (= painted event) is not available to be used with event delegation. Instead 'painted' only fires if you explicily add at least one listener to it, due to performance reason.
Could also be a reason, but I'm not sure.
Best regards,
Schildi
-
11 Oct 2012 11:07 AM #3
Hi Schildi,
i tried initialize event and the result is still the same... The initialize fires only once so the photos are not getting rendered...
The painted event is fired (i check it with logger) as i add a listener to itonFashionCarouselPaintedThere must be another issue...
-
11 Oct 2012 10:36 PM #4
Hi spirosdi,
ah, I looked at your code again and saw another possible error cause.
Probably the problem of the "delay" is, that your store is simply not loaded at this point of time (ajax is asynchronous).
You call, but direclty after that, you want to go through the records with Ext.each(...).Code:storePhotos.load();
What you probably need is the callback functionality of store load, so that you don't loop through the records before the store is loaded.
Try this:
Hope that it does the trick ;-)Code:onFashionCarouselPainted{ storePhotos.load({ callback: function(records, operation, success) { fashionCarousel = Ext.getCmp('FashionCarousel'); fashionCarousel.removeAll(); Ext.each(records, function(current) { fashionCarousel.add({ html: '<h1>' + current.get('title') + '<h1/>' }); }); fashionCarousel.setActiveItem(0); }, scope: this }); }
Best regards,
Schildi
-
11 Oct 2012 11:51 PM #5
You are absolutely right! Thank you!


Reply With Quote