如何解决这个问题?我也尝试了
htmx:xhr:loadend
和htmx:afterrequest
,两者都是同样的问题,只有超时才起作用
document.addEventListener('htmx:afterSwap', function(evt) {
//.... wait for a POST with path /add-song ....
//DOESNT WORK, i cant trigger new HTMX event, immediatly, its ignored
lastSong.dispatchEvent(new Event("play-song-event"));
//WORKS AFTER 1sec
setTimeout(function ()
{
lastSong.dispatchEvent(new Event("play-song-event"));
},1000);
});
找到了,我需要
'htmx:afterSettle'
而不是 'htmx:afterSwap'