Meteor - Stop Tracker Autorun when Template is Destroyed (user leaves page)
在我的 Meteor 模板中,我有一个名为
1 2 3 4 5 6 7 8 9 10 | Template.Live.rendered = function(){ function ohlcInit() { // computations run here } Tracker.autorun(function() { ohlcInit(); }); }; |
当用户在定义了这一切的页面/模板上时,这很有效,但是一旦用户导航到站点上的另一个 URL 并且模板被破坏,控制台中就会抛出错误: Exception from Tracker recompute function: undefined is not a function 当用户导航到新的 URL/模板时,您如何安全地停止/结束自动运行计算?
TypeError: undefined is not a function
at ohlcInit (http://localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaaa9ed200fe3e987:271:33)
at http://localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaaa9ed200fe3e987:306:5
at Tracker.Computation._compute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36)
at Tracker.Computation._recompute (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:302:14)
at Tracker.flush (http://localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:430:14)
我正在使用
使用新的 Template.autorun 函数,它会在模板被销毁后自动清理。要在