简体   繁体   English

多个事件的倒数计时器

[英]countdown timer for multiple events

I've created a very crude system where you ask a builder to complete a task and once that task is complete, the inventory is updated with the outcome of the task. 我创建了一个非常粗糙的系统,您在该系统中要求构建者完成任务,一旦该任务完成,库存就会随着任务的结果而更新。 My problem lies in assigning multiple tasks. 我的问题在于分配多个任务。 If task B completes before task A, then task A gets the inventory update rather than task B. I've never played with setInterval and clearInterval so I'm not sure if my problem lies within how I set up a counter or how the inventory gets updated. 如果任务B在任务A之前完成,那么任务A将获得清单更新而不是任务B。我从没玩过setInterval和clearInterval,所以我不确定我的问题是否出在我如何设置计数器或清单如何得到更新。

http://jsfiddle.net/jawa9000/KFgbj/ http://jsfiddle.net/jawa9000/KFgbj/

See jsfiddle page

Thanks! 谢谢!

I would suggest to use jquery Deferred Objects to be able to set sequence of tasks. 我建议使用jquery Deferred Objects来设置任务序列。

For example, $.ajax() method returns deferred object which has done() property to which you can assign method to be executed when asynchronous call is completed 例如, $.ajax()方法返回具有done()属性的延迟对象,您可以将其分配给异步调用完成后要执行的方法

Thanks for the help but I think I'll go with a solution based off this code: 感谢您的帮助,但我想我将基于此代码提供一个解决方案:

http://codepen.io/anon/pen/Jmpcq/?editors=101 http://codepen.io/anon/pen/Jmpcq/?editors=101

See link

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

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