When doing the following implementation , i get problems because it's look like the data is not available in client side:
In The global configuration of Iron-router , i subscribe to "notifications" publication . Then i fetch the notifications, and i collect the IDs of elements based on type. Then i subscribe to the publications using the collected IDs.
In a template that displays the notifications details, i loop over notifications via Notifications.find() , and then depending on the type of notifications, i do : Questions.findOne(_id) or Answers.findOne(_id) by i am getting undefined exception when i try to access the elements fields.
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
waitOn: function() {
Meteor.subscribe('notifications', function() {
var notifications = Notifications.find().fetch();
var questionsIds = _.map(_.filter(notifications, function (notif) {
return notif.targetObjectType == 'QUESTION';
}), function(q) { return q.targetObjectId});
var answersIds = _.map(_.filter(notifications, function (notif) {
return notif.targetObjectType == 'ANSWER';
}), function(q) { return q.targetObjectId});
Meteor.subscribe('notificationsAnswers', answersIds);
Meteor.subscribe('notificationsQuestions', questionsIds);
How is it possible to wait for the "nested" subscriptions to be ready to use them in helper functions ?