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