简体   繁体   English

在Sencha Touch中更改轮播页面时,触发要运行的功能

[英]trigger a function to run when a carousel's page is changed in Sencha Touch

I'm not sure how many people on here have used the Sencha Touch js library, but I have a question that MUST be simple despite my many attempts and fails. 我不确定这里有多少人使用过Sencha Touch js库,但是我有一个问题,尽管我尝试了很多但失败了,但它必须很简单。 Basically, I have a carousel which pages through results as you swipe, and I want to trigger a function each time a new page is shown. 基本上,我有一个轮播功能,可在您滑动时翻阅结果,并且每次显示新页面时都想触发一个功能。
Anyone have any idea how to do this? 有人知道如何执行此操作吗? I've tried adding a listener to it, and for some reason that doesn't work. 我尝试向其添加一个侦听器,由于某种原因,该方法不起作用。 Something like this: 像这样:

var apCarousel = new Ext.Carousel({
            direction: 'horizontal',
            activeItem: 0,
            ui: 'dark',
            itemId  :   "apCarousel",
            items: pageItems,
            listeners   :   {
                click   :   {
                    element :   this,
                    fn  :   function(){alert('yo!');}
                }
            }
        });

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks. 谢谢。

Use the cardswitch event: 使用cardswitch事件:

Ext.setup({
    onReady: function(){
        new Ext.Carousel({
            fullscreen: true,
            listeners: {
                cardswitch: function(container, newCard, oldCard, index){
                    console.log(container, newCard, oldCard, index);
                }
            },
            items: [{
                html: 'a'
            },{
                html: 'b'
            },{
                html: 'c'
            }]
        });
    }
});

I had the same problem, try to add listener like: 我有同样的问题,尝试添加监听器,如:

listeners: {
             cardswitch:
             {
                fn: function()
                {
                  alert(this.getActiveIndex() );
                }
              },
             }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM