1
我在template.onDestoyed中出现了一个错误和奇怪的行为;无法调用View#从被销毁的回调中订阅
我有代码为无限滚动订阅(它存储在特殊的订阅模板)它工作正常,直到我切换到另一个路由,并创建一个新的实例的订户模板。
代码:
Template.subscriber.onCreated(function() {
var template = this;
var skipCount = 0;
template.autorun(function(c) {
template.subscribe(template.data.name, skipCount, template.data.user);
var block = true;
$(window).scroll(function() {
if (($(window).scrollTop() + $(window).height()) >= ($(document).height()) && block) {
block = false;
skipCount = skipCount + template.data.count;
console.log(template.data);
console.log("skip_count is "+skipCount);
template.subscribe(template.data.name, skipCount, template.data.user, {
onReady: function() {
block = true;
},
onStop: function() {
console.log('route switched, subscribtion stopped');
}
});
}
});
})
});
当我一个页面,用户做工精细,在“向下滚动”当我在另一个页面去和“向下滚动”首先我从老用户模板数据(什么是必须在理论上被破坏)。在第二次(再次向下滚动)用户的新实例开始正常工作。
我做错了什么?