【发布时间】:2016-03-12 17:27:34
【问题描述】:
我在 onRendered 块中遇到了 Meteor ReactiveVar 的问题。这是我的代码:
Template.posts.onRendered(function() {
// get current value for limit, i.e. how many posts are currently displayed
var limit = this.limit.get();
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
// increase limit by 10 and update it
limit += 10;
this.limit.set(limit);
}
});
});
我成功地获得了在console.log() 中测试的限制变量,但是当尝试在$(window).scroll 块中设置它时,我收到以下控制台错误:Uncaught TypeError: Cannot read property 'set' of undefined。我知道这是关于范围界定,但我不知道如何解决这个问题。
【问题讨论】: