在按钮上处理tapStart事件

时间:2013-05-02 22:10:33

标签: events extjs sencha-touch sencha-touch-2 tap

我有一个带旋转木马的应用程序。在所有轮播页面上都有按钮和日期选择器等元素。我想使用Sencha Touch处理每个元素上的tapStart事件,但我无法找到任何允许我这样做的东西。

有没有人有想法?

更新

我也在Sencha论坛上问过这个问题。以下是Sencha论坛主题的链接:http://www.sencha.com/forum/showthread.php?262804-Handle-tapStart-Event-on-a-button&p=963782#post963782

2 个答案:

答案 0 :(得分:1)

您可以尝试使用touchstart,它可以绑定到任何元素,包括按钮

答案 1 :(得分:0)

我在Sencha Touch论坛的帮助下找到了解决问题的方法。

首先,我使用initConfig函数初始化我的容器配置。

Ext.define('MyApp.view.ViewName', {
    ...
    // Very Important, this is what I use in the controller to handle the events
    xtype: 'myxtype', 
    ...
    initConfig: function () {
        var me = this;
        this.config = {
            ...
            items: {
                ...
                {
                    xtype: 'button',
                    ...
                    listeners: {
                        element: 'element',

                        // This is where my code handles the tapstart
                        // (touchstart) event
                        touchstart: function () {
                            // Fire an event on the controller (me)
                            me.fireEvent('buttondown');
                        }
                    }
                },
                ...
            }
        }
        this.callParent([this.config]); // Very Important when using initConfig
    }
});

然后,在我的控制器中,我添加了以下代码:

Ext.define('MyApp.controller.MainController', {
    ...
    config: {
        views: [
            'ViewName',
            ...
        ],
        ...
    },
    ...
    init: function () {
        this.control({
            'myxtype': {
                buttondown: this.myFunction
            }
        })
    },

    myFunction: function () {
        // Do something
    }
});