我正在编写一个插件,它发出事件activating和activated. 我只想在执行activated所有事件处理程序时触发事件activating。我知道$.trigger()同步调用事件处理程序,但问题是我的事件处理程序中可能有一些异步代码:
例子:
$("test").trigger("activating");
$("test").trigger("activated");
$("test").on("activating",function()
{
$.post("/test",{data:"test"},function()
{
//dom modifications here
////////////////
//Here I would like to notify that the event handler is finished, like maybe async.js
}
});
我有一些关于 $.Deferred & Promises 的线索,但我不知道如何实现它们来解决我的具体问题。
有人可以给我解决方案吗?
谢谢