admin管理员组文章数量:1296877
How would I add a click event to each link tag in this other than by building in onclick=....
into the XTemplate?
new Ext.XTemplate(
'<ul>',
'<tpl for="."><li><a href="#{anchor}">{text}</a></li></tpl>',
'</ul>'
).overwrite('someElement', [
{ text: 'Click me', anchor: '1' },
{ text: 'No, click me', anchor: '2'}
]);
How would I add a click event to each link tag in this other than by building in onclick=....
into the XTemplate?
new Ext.XTemplate(
'<ul>',
'<tpl for="."><li><a href="#{anchor}">{text}</a></li></tpl>',
'</ul>'
).overwrite('someElement', [
{ text: 'Click me', anchor: '1' },
{ text: 'No, click me', anchor: '2'}
]);
Share
asked Jan 9, 2012 at 19:41
Mike ThomsenMike Thomsen
37.5k11 gold badges63 silver badges86 bronze badges
1
- Can you provide more code? It depends on control. – Krzysztof Commented Jan 9, 2012 at 20:30
1 Answer
Reset to default 7The short answer is, you don't. Instead, you should use event delegation:
Ext.get('someElement').on('click', function(event, target) {
console.log(target);
}, null, {delegate: 'a'});
This has 2 main advantages:
- You only need to bind a single listener
- It will work as you dynamically modify the content
本文标签: javascriptHow do you attach click events to ExtJS template elementsStack Overflow
版权声明:本文标题:javascript - How do you attach click events to ExtJS template elements? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741645530a2390162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论