1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    5
    Vote Rating
    0
    0nn0 is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Answers
    17
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    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:

    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!");
        }
    });
    You may want to change the delegation to be more specific to the xtypes you need...

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    5
    Vote Rating
    0
    0nn0 is on a distinguished road

      0  

    Default


    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:
    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;'
                    }
                ]);
            }
        });
    http://onnoschwanen.com/prototypes/sencha-dom/

Thread Participants: 1

Tags for this Thread