【问题标题】:Meteor infinite scroll : prevent subscribe to rerender elements流星无限滚动:防止订阅重新渲染元素
【发布时间】: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


【解决方案1】:

我终于明白了,我在 html 中添加了一些代码来等待订阅准备好,但我忘记了。

我删除了:

{{#if Template.subscriptionsReady}}
        {{> Template.dynamic template="t_elementList" data=tabData}}
{{/if}}

无限滚动就像一个魅力。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 2022-07-05
    • 2020-09-22
    • 2020-08-07
    相关资源
    最近更新 更多