我有一个带有轮播的应用程序。在所有轮播页面上都有按钮和日期选择器等元素。我想使用 Sencha Touch 处理每个元素上的 tapStart 事件,但我找不到任何允许我这样做的东西。
有人有想法吗?
更新
我也在 Sencha 论坛上问过这个问题。这是 Sencha 论坛主题的链接:http ://www.sencha.com/forum/showthread.php?262804-Handle-tapStart-Event-on-a-button&p=963782#post963782
我有一个带有轮播的应用程序。在所有轮播页面上都有按钮和日期选择器等元素。我想使用 Sencha Touch 处理每个元素上的 tapStart 事件,但我找不到任何允许我这样做的东西。
有人有想法吗?
更新
我也在 Sencha 论坛上问过这个问题。这是 Sencha 论坛主题的链接:http ://www.sencha.com/forum/showthread.php?262804-Handle-tapStart-Event-on-a-button&p=963782#post963782
您可以尝试使用touchstart可以绑定到任何元素,包括按钮
在 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
}
});