2011-02-24 23 views
7

我試圖創建Ext JS的面板,並得到了上成功,但我也想用這個添加與ExtJS的面板單擊事件

 { 
      xtype: 'panel', 
      flex: 1, 
      x: 10, 
      y: parseInt(panelCreation[i - 1].y) + 
       parseInt(panelCreation[i -1].height) + 10, 
      width: twidth, 
      height: theight, 
      layout: 'absolute'     
     } 

添加單擊事件我不想單獨添加點擊事件我想添加這樣的代碼後佈局:絕對添加逗號和事件請幫助我在這。

回答

23

您可以在一個點擊事件如下補充:

listeners: { 
    'render': function(panel) { 
     panel.body.on('click', function() { 
      alert('onclick'); 
     }); 
    } 
} 

編輯:讓X和click事件,您可以更改Click事件處理程序如下Y座標...

panel.body.on('click', function(e) { 
    alert('X: ' + e.getPageX()); 
    alert('Y: ' + e.getPageY()); 
}); 
+0

我已經發現,但無論如何感謝柯克沃爾你的迴應那工作正常。 – 2011-02-26 21:15:27

+0

@Jaitsu,不想發表另一個問題,但如何獲得點擊座標? – k102 2012-02-27 07:55:52

+0

@ k102我編輯了我的答案 – JamesHalsall 2012-02-27 13:11:01

3
new Ext.Panel({ 
    title: 'The Clickable Panel', 
    listeners: { 
     render: function(p) { 
      // Append the Panel to the click handler's argument list. 
      p.getEl().on('click', handlePanelClick.createDelegate(null, [p], true)); 
     }, 
     single: true // Remove the listener after first invocation 
    } 
}); 
+0

朋友,請您發佈可點擊折線圖的代碼。 – 2012-04-13 13:05:28

+0

我發現這個答案比接受的更好,因爲它也會在標題處執行單擊時觸發事件。 – Aebsubis 2014-03-14 17:13:45

2

還有的,在我看來,一個更簡單的方法來做到這一點...(直取出docs的)。有關添加偵聽器的更多信息,請參閱here。 (分機Js 4)

new Ext.panel.Panel({ 
    width: 400, 
    height: 200, 
    dockedItems: [{ 
     xtype: 'toolbar' 
    }], 
    listeners: { 
     click: { 
      element: 'el', //bind to the underlying el property on the panel 
      fn: function(){ console.log('click el'); } 
     }, 
     dblclick: { 
      element: 'body', //bind to the underlying body property on the panel 
      fn: function(){ console.log('dblclick body'); } 
     } 
    } 
});