Extjs 如何为combobox afterSubTpl内容配置单击事件侦听器
这里我使用的是ExtJS5 我的用例是在组合框输入框下面显示一些文本。因此,我使用combobox的“afterSubTpl”配置并显示所需的文本。 现在,当用户单击上面指定的文本时,我必须引发一个事件 组合框在Ext JS中不应包含单击事件。如何为此配置单击事件侦听器Extjs 如何为combobox afterSubTpl内容配置单击事件侦听器,extjs,combobox,extjs5,Extjs,Combobox,Extjs5,这里我使用的是ExtJS5 我的用例是在组合框输入框下面显示一些文本。因此,我使用combobox的“afterSubTpl”配置并显示所需的文本。 现在,当用户单击上面指定的文本时,我必须引发一个事件 组合框在Ext JS中不应包含单击事件。如何为此配置单击事件侦听器 // The data store containing the list of states var states = Ext.create('Ext.data.Store', { fields: ['abbr', '
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});
// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
afterSubTpl: '<div>My Custom Text</div>',
renderTo: Ext.getBody()
});
//包含状态列表的数据存储
var states=Ext.create('Ext.data.Store'{
字段:['abbr','name'],
数据:[
{“abbr”:“AL”,“name”:“Alabama”},
{“abbr”:“AK”,“name”:“Alaska”},
{“abbr”:“AZ”,“name”:“亚利桑那州”}
]
});
//创建附加到状态数据存储的组合框
Ext.create('Ext.form.ComboBox'{
fieldLabel:“选择状态”,
商店:美国,
queryMode:'本地',
displayField:'名称',
valueField:'缩写',
afterSubTpl:“我的自定义文本”,
renderTo:Ext.getBody()
});
需要为红色边框显示的文本配置单击事件。如果是代码,您可以执行以下操作:
listeners: {
afterrender: function(component) {
var myDiv = component.getEl().down('div#myDiv');
myDiv.on('click', function() {
console.log('Clicked!');
});
}
}
对于您的代码,您可以执行以下操作:
listeners: {
afterrender: function(component) {
var myDiv = component.getEl().down('div#myDiv');
myDiv.on('click', function() {
console.log('Clicked!');
});
}
}
您可以向div添加一个类,然后在
单击事件上使用元素和委派,如:
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
afterSubTpl: '<div class="foo">My Custom Text</div>',
renderTo: Ext.getBody(),
listeners: {
click: {
element: 'el',
delegate: '.foo',
fn: function(){
console.log('click');
}
}
}
});
Ext.create('Ext.form.ComboBox'{
fieldLabel:“选择状态”,
商店:美国,
queryMode:'本地',
displayField:'名称',
valueField:'缩写',
afterSubTpl:“我的自定义文本”,
renderTo:Ext.getBody(),
听众:{
点击:{
元素:“el”,
代表:'.foo',
fn:函数(){
console.log('click');
}
}
}
});
您可以向div添加一个类,然后在单击事件上使用元素和委派,如:
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
afterSubTpl: '<div class="foo">My Custom Text</div>',
renderTo: Ext.getBody(),
listeners: {
click: {
element: 'el',
delegate: '.foo',
fn: function(){
console.log('click');
}
}
}
});
Ext.create('Ext.form.ComboBox'{
fieldLabel:“选择状态”,
商店:美国,
queryMode:'本地',
displayField:'名称',
valueField:'缩写',
afterSubTpl:“我的自定义文本”,
renderTo:Ext.getBody(),
听众:{
点击:{
元素:“el”,
代表:'.foo',
fn:函数(){
console.log('click');
}
}
}
});