How to get the source element on a button click event handler? iView

303 Views Asked by At

In iView, all UI elements are rendered by return data of "render" function, for example , i have the following data:

h('Button', {
props: {
    type: 'warning',
    size: 'small',
    disabled: params.row.disabled
},
style: {
    marginTop: '5px',
    marginRight: '5px',
    marginBottom: '5px'
},
on: {
    click: () => {
        this.checkDataOne(params.row);
    }
}
}, 'check data')

which will show a button. I want to disable this button on the beginning of click event, and enable it in the end(there's an asynchronous operation in checkDataOne function). But how can i get the button?

I tried "window.event.srcElement", but it return a span element, which is enclosed in the button.

1

There are 1 best solutions below

1
T. Dirks On

If you can use window.event.srcElement to get the span element inside the button, you can look for the closest button element surrounding it.

So your code to get the source element would become:

window.event.srcElement.closest("button");

You can change the "button" to any specific selector you need in order to target the button.