-
19 Feb 2012 1:00 PM #1
Unanswered: Carousel - How to listen for item appended to DOM
Unanswered: Carousel - How to listen for item appended to DOM
Hi there!
Continued tinkering with Sencha Touch 2 and bumped into the following problem.
When I instantiate a carousel component and add x amount of items to it, how do I know when these items are appended to the DOM?
Looks like the "add" event gets dispatched when the item is added to the carousel != the DOM.
Is there a way in the framework to listen for this?
Sample:
http://onnoschwanen.com/prototypes/sencha-dom/
Code:var carousel; Ext.application({ name: 'Proto', launch: function() { carousel = Ext.create('Ext.Carousel', { fullscreen: true, direction: 'vertical', listeners: { add: function(carousel, item, index, eOpts) { console.log('item added', carousel, item, index); console.log(item.id, document.getElementById(item.id) ); item.addListener() }, painted: function() { console.log('painted'); } } // end listeners }); // end carousel carousel.add( { style: 'background-color: #96d3d7; color: white;', }, { style: 'background-color: #80bec2; color: white;', }, { style: 'background-color: #96d3d7; color: white;', }, { style: 'background-color: #80bec2; color: white;', }, { style: 'background-color: #96d3d7; color: white;', }, { style: 'background-color: #80bec2; color: white;', } ); } // end launch }); // end Ext.application
-
19 Feb 2012 1:44 PM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,653
- Vote Rating
- 14
- Answers
- 17
As done in your example code, the painted event would fire when the carousel is added to the dom, not when the items within it. haven't tried it but this should work...
You delegate a listener to find the containers you are adding:
You may want to change the delegation to be more specific to the xtypes you need...Code:Ext.define('Ext.ux.myCarousel', { extend: 'Ext.carousel.Carousel', initialize: function() { this.callParent(); this.on({ painted: 'onItemPainted', delegate: 'container', scope: this }); }, onItemPainted: function(item) { console.log("I'm in the DOM now!"); } });
-
20 Feb 2012 6:45 AM #3
Thanks for the quick response Jamie!
Gave your suggestion a shot, but somehow it doesn't catches the painted event that is getting dispatched for each item.
What am I missing here?
Quick test:
http://onnoschwanen.com/prototypes/sencha-dom/Code:Ext.define('Ext.ux.myCarousel', { extend: 'Ext.carousel.Carousel', initialize: function() { this.callParent(); this.on({ painted: 'onItemPainted', delegate: 'container', scope: this }); }, onItemPainted: function(item) { console.log("I'm in the DOM now!", item); } }); Ext.application({ name: 'Proto', launch: function() { var carousel = Ext.create('Ext.ux.myCarousel', { fullscreen: true, direction: 'vertical', }); carousel.add([ { style: 'background-color: #80bec2; color: white;' }, { style: 'background-color: #96d3d7; color: white;' }, { style: 'background-color: #80bec2; color: white;' }, { style: 'background-color: #96d3d7; color: white;' }, { style: 'background-color: #80bec2; color: white;' } ]); } });


Reply With Quote