如何将onclick事件附加到XTemplate元素extjs? [英] how to attach onclick event to XTemplate element extjs?
本文介绍了如何将onclick事件附加到XTemplate元素extjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是代码。
请帮助,谢谢提前。
var resultTemplate = new Ext.XTemplate(
' tpl for =。>',
'< div class =list-itemid = {value}>',
'< i class =folder-icon> ;& nbsp;< / i>',
'{value}',
'< / div>',
'< / tpl>'
) ;
Ext.define('abc.view.xyz',{
layout:{
type:'border',
padding:5
},
extends:'Ext.Panel',
alias:'widget.infraTab',
id:'infraTab',
margin:'10 10 10 10 ',
border:true,
items:Ext.create('Ext.view.View',{
store:store,
tpl:resultTemplate
})
});
我想要div与class list-item
clicked和其id的值。
解决方案
你应该可以使用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'));
}
}
});
这是一个 Sencha Fiddle 演示其使用。
I am very new to extjs. I want to call onclick event once I click on div, Below is the code. Please help, Thanks in advance.
var resultTemplate = new Ext.XTemplate(
'<tpl for=".">',
'<div class="list-item" id={value}>',
'<i class="folder-icon"> </i>',
'{value}',
'</div>',
'</tpl>'
);
Ext.define('abc.view.xyz', {
layout : {
type: 'border',
padding: 5
},
extend : 'Ext.Panel',
alias : 'widget.infraTab',
id : 'infraTab',
margin : '10 10 10 10',
border : true,
items : Ext.create('Ext.view.View', {
store: store,
tpl:resultTemplate
})
});
I want the div with class "list-item"
clicked and the value of its id.
解决方案
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.
这篇关于如何将onclick事件附加到XTemplate元素extjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文