We use XTemplates - lots of XTemplates. They are great for displaying read-only content. But have you ever added (Ext JS) listeners to DOM created via a template? Would y
The simplest approach we adopt here is the following:
// Function to be called on DOM event
var functionCallback = function () {
console.log('hello');
}
// function to bind elements created via XTemplate and DOM events
function bind(Ext.Element element, String selector, Obj callback) {
var els = element.query(selector);
Ext.Array.each(els, function (item, index, allItems) {
item.addEventListener('click', callback, false);
});
}
And the usage:
var tpl = new Ext.XTemplate(...);
var data = [..]
var returnedEl = tpl.append(otherElem, data, true);
bind(returnedEl, 'div.my-css-class', functionCallback);