我有一個面板,我使用下面的代碼呈現。Extjs面板。鍵盤事件
new Ext.Panel({
id: 'textPanel',
height: 1000,
width: 1200,
renderTo: Ext.getBody(),
html:"An HTML fragment, or a DomHelper specification to use as the layout element content. The HTML content is added after the component is rendered, so the document will not contain this HTML at the time the render event is fired. This content is inserted into the body before any configured contentEl is appended."
});
然後我想在按下回車鍵時收聽事件。所以,我創建一個KeyMap如下...
var map = new Ext.KeyMap(Ext.getCmp('textPanel').body, {
key: Ext.EventObject.ENTER,
fn: onKeyPress,
// handler: onKeyPress,
scope: this
});
但onKeyPress函數沒有被調用。
我一直在使用的
Ext.getCmp('textPanel').body.dom,
Ext.getCmp('textPanel').el.dom,
Ext.getCmp('textPanel').el
代替
Ext.getCmp('textPanel').body
沒有成功已經嘗試過。
如果我在那裏使用「文檔」,那麼會調用onKeyPress函數。即
var map = new Ext.KeyMap(document, {
key: Ext.EventObject.ENTER,
fn: onKeyPress,
// handler: onKeyPress,
scope: this
});
這很好,但我不想聽整個文檔。 我怎樣才能聽到面板?
你是什麼意思「聽面板」嗎?你的面板應該是'TextField'嗎?在一個普通的「Ext.Panel」上聽一個關鍵事件是沒有意義的...... – kevhender
我的面板在它的主體中有文本。我想在面板的主體內按下輸入或製表鍵時做一些事情。 –