如果我添加這樣如何將點擊事件添加到extjs autoel?
xtype: 'component',
autoEl: {
html: '<input type="submit" class="custom_loginbtn" value="Submit" id="login"/>'
}
任何想法按鈕如何將點擊事件添加到這一點?
問候
如果我添加這樣如何將點擊事件添加到extjs autoel?
xtype: 'component',
autoEl: {
html: '<input type="submit" class="custom_loginbtn" value="Submit" id="login"/>'
}
任何想法按鈕如何將點擊事件添加到這一點?
問候
嘗試添加監聽
listeners: {
render: function(component){
component.getEl().on('click', function(e){
console.log(component);
alert('test');
});
}
}
檢查this
您使用的是標準的提交按鈕,爲什麼不使用的xtype按鈕? - 它可以爲您的點擊事件指定一個處理程序。
,因爲我需要使用一個CSS樣式的按鈕,而不是extjs按鈕 – 2012-01-04 13:32:15
你看看樣式extjs按鈕?或使用背景圖像? – dbrin 2012-01-04 17:44:35
我嘗試申請的yup風格不適用於extjs默認按鈕,雖然 – 2012-01-05 19:50:50
xtype : 'component',
itemId : 'submitbtn',
autoEl : {
html : '<input type="submit" class="custom_loginbtn" value="Login" id="login"/>'
},
listeners : {
el : {
delegate : 'input',
click : function()
{
}
}
}
這是最好的方法,注意代替.on()
這是更好地與.mon()
使用管理聽衆的,當你從可能被損壞的元器件聽DOM元素使用
xtype: 'component'
,html: '<input type="submit" class="custom_loginbtn" value="Submit" id="login"/>'
,listeners: {
afterrender: function(inputCmp) {
inputCmp.mon(inputCmp.el, 'click', function(){alert('click!')}, this, {delegate:'input'});
}
,single: true
}
此外,您使用autoEl類似於設置組件的html屬性,autoEl中的其他選項允許您操作自動創建的外部標籤的類型和屬性以包含組件
如果你這樣做,而不是你可以把關閉組件本身爲<input>
,避免包裝<div>
:
xtype: 'component'
,autoEl: {
tag: 'input'
,cls: 'custom_loginbtn'
,type: 'submit'
,value: 'Submit'
}
,listeners: {
afterrender: function(inputCmp) {
// no delegate needed, since inputCmp.el is the <input>
inputCmp.mon(inputCmp.el, 'click', function(){alert('click!')}, this);
}
,single: true
}
小心這一點。您的渲染偵聽器將添加一個onClick事件到底層元素,但渲染事件可能會再次觸發。 – dbrin 2012-01-03 17:52:46
謝謝。找到了另一種解決方案,我會發布它 – 2012-01-04 13:33:53