how to attach onclick event to XTemplate element extjs?

≡放荡痞女 提交于 2019-12-06 15:41:14

You should be able to use the itemclick listener:

Ext.create('Ext.view.View', {
     store: store,
     tpl: resultTemplate,
     itemSelector: '.list-item',
     listeners: {
         itemclick: function(view, record, item, index, e, eOpts) {
             alert(record.get('value'));
         }
     }
});

Here is a Sencha Fiddle demonstrating its use.

When you are NOT using a View then itemSelector is not available, in such cases you can do something like:

afterRender: function () {
        this.callParent(arguments);

        this.el.select('.item', true)
            .elements
            .forEach((item) =>
                item.on('click', (e, element) => {
                        this.fireEvent('itemclick');
                    }
                )
            );
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!