【发布时间】:2015-08-27 18:44:43
【问题描述】:
我在 Template.prototype.onRendered() 中使用 Template.prototype.autorun() 来响应式更新模板。我想要多次自动运行,所以只有更新数据的部分会再次运行。这是我想象中的样子:
...
for d in [0..6]
@autorun ->
console.log d
deplanements = [ 'deplanements' ]
for h in [0..23]
deplanements[h + 1] = 0
Flights.find(
eibt:
$gte: new Date(
weekStart.year(), weekStart.month(), weekStart.date() + d, h
)
$lt: new Date(
weekStart.year(), weekStart.month(), weekStart.date() + d, h + 1
)
).forEach (flight) ->
deplanements[h + 1] += flight.passengers
charts[d].load columns: [
xLabels
deplanements
[]
]
在第一次渲染时它工作正常,在控制台中我看到 0, 1... 6 并且模板看起来像预期的那样。但是,当我修改集合时, d 打印为 7。我不明白这是怎么可能的。如果我手动展开循环,它工作正常:
...
@autorun ->
d = 0
console.log d
...
@autorun ->
d = 1
console.log d
...
...
【问题讨论】:
标签: meteor