我正在尝试在 Ext JS 4 中创建自己的 LinkButton 组件。没什么新意,对吧?
我的代码如下所示:
Ext.define('LinkButton', {
extend: 'Ext.Component',
xtype: 'linkbutton',
autoEl: 'a',
renderTpl: '<a href=\"javascript:;\">{text}</a>',
config: {
text: '',
handler: function () { }
},
initComponent: function () {
var me = this;
me.callParent(arguments);
this.renderData = {
text: this.getText()
};
var handler = me.getHandler();
if (handler) {
me.on('click', handler);
}
}
});
到目前为止,一切都很好!我的 LinkButton 看起来确实像一个超链接,我的文本内容就在那里。优美。
但是,当我单击组件时,我无法让组件触发事件!
这条特定的线路me.on('click', handler);
is not在职的!即使我改变它on to 添加监听器它没有效果。
所以问题是:如何将 DOM 事件添加到我的组件中?或者,更好的是,我该如何access我自己的组件的 DOM 元素?这些我都没能做到!
Thanks!
或者你可以这样做
afterRender : function() {
this.callParent(arguments);
this.mon(this.el, {
scope : this,
delegate : 'a',
click : this.handleClick
});
},
handleClick : function(e, t) {
e.stopEvent();
var handler = this.getHandler();
if (handler) {
handler();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)