简体   繁体   English

在一个<div>元素如何优先处理 href 和 onClick 调用?

[英]On a <div> element how to prioritize the href and onClick calls?

I have a code where on clicking on a file name, the file is downloaded (making backend call) and a store needs to be reloaded to track this file download event (by a backend call again).我有一个代码,点击文件名,文件被下载(进行后端调用),并且需要重新加载商店以跟踪此文件下载事件(再次通过后端调用)。

'<div id ="myId"> <a  onClick="reloadStore()" href="/downloadFile/' + fileId + '.pdf" > MyFileName</a></div>'

reloadStore = function(){
//do something
}

I want the file download call to be made before the onClick call is made.我希望在进行 onClick 调用之前进行文件下载调用。 I even tried to write the code as follows but I still get the same result.我什至尝试按如下方式编写代码,但仍然得到相同的结果。

'<div id ="myId"> <a  href="/downloadFile/' + fileId + '.pdf" > MyFileName</a></div>'

Ext.get('myId').on('click', function(eventObj, elRef) {
                        //do something 
                    });

How can the href call precede the onClick call? href 调用如何先于 onClick 调用?

You'd have to do a simple delay:你必须做一个简单的延迟:

Ext.get('myId').on('click', function() {
}, null, { delay: 1 });

This will put the handler into an asynchronous setTimeout which will then execute after the current javascript thread is executed.这会将处理程序放入异步 setTimeout 中,然后将在当前 javascript 线程执行后执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM