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
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 setTimeout
s 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.