8
我正在为游戏创建一个简单的倒数计时器。我正在使用CoffeeScript和Meteor。我有一个带有{{time}}表达式的Handlebars“Timer”模板。流星JS中的简单定时器
下面是代码:
clock = 10
timeLeft =() ->
if clock > 0
clock--
else
"That's All Folks"
Meteor.clearInterval(interval)
interval = Meteor.setInterval(timeLeft, 1000)
if Meteor.isClient
Template.timer.time = interval
上面的代码只是给我的8静态显示或6代替倒数计时器。
如果我添加一些console.log语句,我可以看到它在终端中按照设计工作。
clock = 10
timeLeft =() ->
if clock > 0
clock--
console.log clock
else
console.log "That's All Folks"
Meteor.clearInterval(interval)
interval = Meteor.setInterval(timeLeft, 1000)
if Meteor.isClient
Template.timer.time = interval
谢谢Akshat。工作很好。 – ppedrazzi 2013-03-05 18:29:40