1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    66
    Vote Rating
    0
    stirucherai is on a distinguished road

      0  

    Default How to get correct active item as part of activeitemchage on carousel

    How to get correct active item as part of activeitemchage on carousel


    I have carousel with 5 items. I have added following code
    Code:
        		Ext.ComponentMgr.get("Carousel").on("activeitemchange", function(me, value, oldValue, index)
        		{
        				console.log(this.getActiveIndex());
        		});
    Following is what gets displayed on console
    -1 when carousel is loaded (with 5 items)
    0 when swiped to second item (left to right swipe)
    1 when swiped to third item
    2 when swiped to fourth item
    3 when swiped back to third item (right to left swipe)
    2 when swiped back to second item
    1 when swiped back to 3rd item
    2 when swiped back to 4th item

    so the getActiveItem is not show correct value. "activeitemchange" event gets triggered after item has been switched and hence thought getActiveItem will give correct value

    What am I doing wrong. I need the current Index of the item that is being changed to.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,328
    Vote Rating
    849
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Code:
    Ext.create('Ext.carousel.Carousel', {
        fullscreen   : true,
        items        : [
            {
                html : 'one'
            },
            {
                html : 'two'
            },
            {
                html : 'three'
            },
            {
                html : 'four'
            }
        ],
        listeners : {
            activeitemchange: function(carousel, newCard) {
                console.log(carousel.getInnerItems().indexOf(newCard));
            }
        }
    });
    Looks like the activeIndex is being set after the activeitemchange is happening as getActiveIndex() should return the proper index when the activeitemchange happens. The above code will get the proper index.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    66
    Vote Rating
    0
    stirucherai is on a distinguished road

      0  

    Default


    Great it works. Thanks a lot.

Thread Participants: 1