Issue With Subscriptions On Multiple Instances Of A Template
Here is the scenario. I have a template that contains a #each loop and renders an instance of a particular template, setting the data context on each template as per the docs. <
Solution 1:
The problem is with this.data._id
in your subscription, which right now is scoped to the innermost function. You want instance.data._id
(which is nonreactive so you wouldn't need an autorun
) or Template.currentData()
(which is reactive).
Template.runway_panel.onCreated(function(){
var instance = this;
instance.autorun(function(){
var data = Template.currentData();
var subscription = instance.subscribe('runway_status', data._id);
});
});
Also note that in your publication, you should mark it as this.ready()
if this.userId
is undefined
. But that's not the source of the error.
Solution 2:
First, userId is a function and userId() would return current user id. And you could check here to learn more detail of instance.subscribe
.
I think your problem may happen in getting runway._id
in Meteor.publish
Template.runway_panel.onCreated(function(){
var instance = this;
// instance subscribe data whose _id is runwayPanelId
instance.autorun(function(){
var dataContext = Template.currentData();
var subscription = instance.subscribe('runway_status', dataContext.runwayPanelId);
});
instance.status = function(){
returnRunway_Status.find();
}
});
// publicationMeteor.publish('runway_status', function(runway){
// using Meteor.userId() to get current user idif(Meteor.userId()){
//Retrieve the last know status for the given runwayreturnRunway_Status.find({runway: runway});
}
});
<templatename = 'live'><divclass = 'row'>
{{#each runways}}
<divclass = 'col-md-2'>
{{> runway_panel runwayPanelId=_id}}
</div>
{{/each}}
</div></template>
Post a Comment for "Issue With Subscriptions On Multiple Instances Of A Template"