Jon*_*rsi 11 javascript mongodb meteor meteor-tracker
在我的Meteor模板中,ohlcInit()当Mongo中有新数据时,我有一个名为autorun 的函数:
Template.Live.rendered = function(){
function ohlcInit() {
// computations run here
}
Tracker.autorun(function() {
ohlcInit();
});
};
Run Code Online (Sandbox Code Playgroud)
当用户在页面/模板上进行定义时,这非常有用,但只要用户导航到站点上的另一个URL并且模板被销毁,就会在控制台中抛出错误:
Tracker重新计算函数的异常:undefined不是函数TypeError:undefined不是函数在ohlcInit(http:// localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaa99002009e987:271:33)的http:// 在Tracker.Computation上的localhost:3000/client/views/live/live.js?dd5fb618daf9ea9e233c37caaa9ed200fe3e987:306:5在Tracker.Computation._compute(http:// localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:288:36) .rcompute(http:// localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:302:14)在Tracker.flush(http:// localhost:3000/packages/tracker.js?192a05cc46b867dadbe8bf90dd961f6f8fd1574f:430:14)
当用户导航到新的URL /模板时,如何安全地停止/结束自动运行计算?
我在用iron:router.
Dav*_*don 16
使用新的Template.autorun函数,该函数在模板被销毁后自动清理.要在rendered回调中使用它,只需替换Tracker.autorun为this.autorun.
| 归档时间: |
|
| 查看次数: |
3545 次 |
| 最近记录: |