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
There are a few options:
Meteor.call and Meteor.methods call pair. You could also put the result in a reactive variable so the template automatically re-renders.As you may have already discovered, the onReady event of subscribe() fires when the publish method calls ready(), not when all the data has shipped over.
Here's a simple example of #3 above:
In the client:
Meteor.call('get_complete_email',id, function(err,doc) {
if (err === undefined) {
// Note current_compose is reactive
current_compose.set(new _ComposePresenter(action, doc));
} else {
log_error('compose','get complete email ',err);
}
});
In the server:
Meteor.methods({
'get_complete_email': function(id) {
return Emails.findOne({_id:id, user_id:Meteor.userId}, body_message_fields);
}
});
In your presenter or viewer code: (the data temp variable could be eliminated - it's legacy and hasn't been refactored out yet).
Template.compose_to_cc_bcc_subject.prefilled = function(part) {
if (Current && Current.compose()) {
var data = Current.compose();
if (data == undefined || data[part] == undefined) { return; }
return data[part];
} else {
return;
}
}
Obviously, you'll need to wire up current_compose, Current and your own objects a little differently.