Callback when all Template items finished rendering in Meteor?

前端 未结 7 991
-上瘾入骨i
-上瘾入骨i 2020-12-19 09:30

I\'m getting a collection of records and placing them in a Template, having them rendered {{#each}} and I want to display a loading icon until the last DOM node

7条回答
  •  独厮守ぢ
    2020-12-19 10:03

    In my case, a partial solution is this:

    Add the onComplete() callback to the subscriptions of my Items collection, which is the official end of any loading process. So, no more hacky setTimeouts in Template.rendered, just set loading_stuff to true when data is queried (in Template.stuff.items) and then to false in the onComplete() callback in the subscribe function:

    Server:

    Meteor.publish('items', function (some_param) {
        return Items.find({some_field: some_param});
    });
    

    and Client:

    Meteor.subscribe('items', some_param, function onComplete() {
        Session.set('loading_stuff', false);
    });
    

    ...

    Template.stuff.items = function () {
        Session.set('loading_stuff', true);
        return Items.find({owner: Meteor.userId()}, {sort: {created_time: -1}});
    };
    

    It's a partial solution because knowing when the data has arrived from the server and when the DOM has finished rendering are two separate issues.

提交回复
热议问题