【发布时间】:2017-01-04 03:13:56
【问题描述】:
我正在 Meteor 上实现无限滚动,以显示链接到大型收藏的图片网格。
当用户在页面末尾时,我订阅了更多元素并增加了显示的图片数量(通过我的 template.helper)。
//SERVER
Meteor.publish('generalMusics', function(limit){
return Musics.find({}, {limit: limit});
});
//CLIENT: when the template is created and when the limit of data increases
//it subscribes again
Template.t_elementSubHeader.onCreated( function() {
Session.set('reqLimit',50);
var self = this;
//Everytime reqLimit changes I redo the subscribe
this.autorun(function(){
self.subscribe('generalMusics', Session.get('reqLimit'));
});
//CLIENT: more elements are sent to the template when reqLimit increases
Template.t_elementSubHeader.helpers({
data: function() {
return Musics.find({}, {limit : Session.get('reqLimit')});
}
});
//Also on client, when the user reach the bottom of the page
Session.set('reqLimit',Session.get('reqLimit')+50);
它运行良好,但所有模板元素都在重新渲染,而且还需要一些时间。这对用户来说非常不方便,我认为这需要时间,因为我显示的是图片而不是文本(我们已经将图片压缩到最小尺寸)。
问题是由于重新呈现所有模板元素的订阅。
如何在订阅时只添加新元素并防止重新呈现已显示的元素?
我的应用程序将在移动设备上,所以我不能订阅很多元素,然后只增加模板助手中的限制。
【问题讨论】:
-
一些代码确实有助于诊断问题
-
我加了一个例子
标签: meteor publish-subscribe infinite-scroll