Events order between DOM event and sencha event

一曲冷凌霜 提交于 2021-02-11 14:35:43

问题


I've a dataview, written with extjs 7.1 modern tookit, with a template with an anchor tag and a select event:

https://fiddle.sencha.com/#view/editor&fiddle/34bd

Ext.create({
    renderTo: document.body,

    xtype: 'list',
    itemTpl: '<div class="contact"><a onclick="event.preventDefault();console.log(\'link\');" href="{firstName}">{firstName}</a> <b>{lastName}</b></div>',

    store: {

        data: [{
            firstName: 'Peter',
            lastName: 'Venkman'
        }, {
            firstName: 'Raymond',
            lastName: 'Stantz'
        }, {
            firstName: 'Egon',
            lastName: 'Spengler'
        }, {
            firstName: 'Winston',
            lastName: 'Zeddemore'
        }]
    },
    listeners: {
        select() { console.log('select'); }
    }
});

I expect the link event will be fired before the list select event, but the opposite happens and even worst both events will be fired one after another.


回答1:


I'm trying to understand where the user clicks as you suggest but I don't know how.

As @LightNight said, you can use childtap event to run needed handler before select. If you want to understand where the click occurred - just use event.target. Look my example




回答2:


how about onItemDisclosure property of list instead of a link?

use onItemDisclosure function and select listener to separate two actions.

onItemDisclosure : Boolean / Function / String / Object BINDABLE

Set to true to display a disclosure icon on each list item. The list will then fire the disclose event, and the event can be stopped before childtap. By setting this config to a function, the function passed will be called when the disclosure is tapped. This can be either a function object or the name of a Ext.app.ViewController method.

Finally you can specify an object with a scope and handler property defined. This will also be bound to the tap event listener and is useful when you want to change the scope of the handler.

xtype: 'list',
itemTpl: [
    '<div class="contact">',
    '<b>',
    '{firstName} {lastName}',
    '</b>',
    '</div>'
],
onItemDisclosure: function (record, btn, index) {
    console.log('Disclosure');
    Ext.Msg.alert('Tap', 'Disclose more info for ' + record.get('firstName'), Ext.emptyFn);
},
store: {

    data: [{
        firstName: 'Peter',
        lastName: 'Venkman'
    }, {
        firstName: 'Raymond',
        lastName: 'Stantz'
    }, {
        firstName: 'Egon',
        lastName: 'Spengler'
    }, {
        firstName: 'Winston',
        lastName: 'Zeddemore'
    }]
},
listeners: {
        select() {
            console.log('select');
        }
}

here is fiddle example



来源:https://stackoverflow.com/questions/60621082/events-order-between-dom-event-and-sencha-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!