Results 1 to 3 of 3

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

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    66
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,411
    Vote Rating
    1290
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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
      0  

    Default

    Great it works. Thanks a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •