在我的列表视图中,我将addEventListener
(别名on
)放入initialize
事件中
initialize: function (component) {
component.element.on({
tap: {
scope: this,
fn: 'onTap',
delegate: 'div.side-itemDelete'
}
});
},
但是如果有更多delegate
(其他带id或类的元素)我需要绑定一个事件,我该如何处理呢?
这是我的XTemplate:
new Ext.XTemplate(
'<div class="side-weatherListItem no-dragging">',
'<div class="side-itemLocation">',
'<div>{[values.city.toUpperCase()]}</div>',
'<div>{[values.text.toUpperCase()]}</div>',
'</div>',
'<div class="side-itemTemperature">{temp}°{unit}</div>',
'<div class="side-itemState">',
'<div><img src="./resources/img/rain.svg"></div>',
'<div class="side-itemDate">11:38</div>',
'</div>',
'<div class="side-itemDelete" fire="onDelete">', // <<---- here
'<img src="./resources/img/delete.svg">',
'</div>',
'</div>'
),
答案 0 :(得分:2)
您需要指定多个侦听器:
{
xtype: 'list',
listeners: [
{
event: 'tap',
fn: function(){
console.log('delete');
},
element: 'innerElement',
delegate: '.side-itemDelete'
},
{
event: 'tap',
fn: function(){
console.log('locate');
},
element: 'innerElement',
delegate: '.side-itemLocation'
}
]
}