jQuery 插件中的链接函数
我编写了一个小插件来处理文本到输入到文本字段以进行即时编辑,并且它包含允许用户在过程的不同时间间隔运行函数的参数。
我希望用户能够单击“执行器”(控制过程的元素),并选择在单击按钮后运行一个干预函数(函数 A),并选择在返回字段后运行另一个函数转换为标准文本(功能 B)。
假设函数 A 通常包含某种异步调用。如何使功能 B 在功能 A 完成后强制运行?我试图避免必须传递某些值来将函数“标记”为就绪的情况。
I wrote a small plugin to handle text-to-input-to-text fields for on-the-fly editing, and it includes arguments that allow a user to run functions at different intervals of the process.
I want the user to be able to click the "actuator" (the element that controls the process), and choose to have an intervening function run after the button is clicked (Function A) and another to run after the field has been turned back into standard text (Function B).
The assumption is that Function A will generally contain some sort of asynchronous call. How do I make it so that Function B is forced to run after Function A completes? I'm trying to avoid situations where certain values have to be passed to "flag" a function as ready.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然还没有答案,那我就来试试吧。我想我知道你想做什么。
您的所有异步调用都将有一个可选的回调。因此,您可以调用其中的函数,也可以设置一些自定义事件。
http://api.jquery.com/bind/
然后您可以将事物“绑定”到这些事件。因此,当该事件或函数调用时,其他函数也会调用。本质上是事件处理程序和听众。
因此,当您的应用程序中发生不同的事情时,只需让事件侦听事件,并自行打开或关闭它们是否可以在任何给定时间激活或使用。
您也可以这样做,因为我认为您最初尝试使用布尔标志,但这可能会变得非常混乱,具体取决于您有多少个标志。
Since there hasn't been an answer yet, I'll give it a shot. I think I know what you are trying to do.
All your async calls will have an optional callback. So you can call a function in that or you can also setup some custom events.
http://api.jquery.com/bind/
Then you can 'bind' things to those events. So other functions call when that event or function calls. Essentially event handlers & listeners.
So as different things happen in your application just have things listening to the events, and toggling themselves on or off on whether they can be activated or used at any given time.
You could also do this as I think you were initially attempting with using boolean flags but that could get pretty messy depending on how many you have.