2013-05-02 45 views
0

我有一個應用程序與旋轉木馬。在所有輪播頁面上都有諸如按鈕和日期選擇器等元素。我想使用Sencha Touch來處理這些元素上的tapStart事件,但是我一直無法找到任何讓我做到這一點的事情。在按鈕上處理tapStart事件

有沒有人有想法?

UPDATE

我問的煎茶論壇這個問題爲好。這裏是鏈接到煎茶論壇主題:http://www.sencha.com/forum/showthread.php?262804-Handle-tapStart-Event-on-a-button&p=963782#post963782

+0

你有什麼代碼這麼遠? – Chris 2013-05-02 22:12:06

+0

@ChrisBain這是我的問題其實,我真的沒有任何代碼。我所有的是在旋轉木馬的每個容器上都有各種元素的旋轉木馬。 – 2013-05-03 01:12:15

回答

0

我想出了一個解決我的問題從煎茶觸摸論壇上尋求幫助的任何元素。

首先我使用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 
    } 
});