javascript - Issue with subscriptions on multiple instances of a template -
here scenario. have template contains #each loop , renders instance of particular template, setting data context on each template per docs.
<template name = 'live'> <div class = 'row'> {{#each runways}} <div class = 'col-md-2'> {{> runway_panel}} </div> {{/each}} </div> </template>
and helper backing it:
template.live.helpers({ runways: function(){ return runway_data.find(); } });
this works, issue follows. each live_event_log instance has template level subscription subscribes publication takes _id parameter of data context, so:
template.runway_panel.oncreated(function(){ var instance = this; instance.autorun(function(){ var subscription = instance.subscribe('runway_status', this.data._id); }); instance.status = function(){ return runway_status.find(); } });
this publication:
meteor.publish('runway_status', function(runway){ if(this.userid){ //retrieve last know status given runway return runway_status.find({runway: runway}); } });
this when falls apart, on browser console:
[log] exception in queued task: http://localhost:3000/client/views/live/runway_panel.js?4efaac87b39527d3dfd3d65a174520f9bce3c565:4:73 (meteor.js, line 888)_withtemplateinstancefunc@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:3476:16 http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:1864:54 _withcurrentview@http://localhost:3000/packages/blaze.js?a5c324925e5f6e800a4c618d71caf2848b53bf51:2197:16
as comment out subscription line else works, missing obvious here? have multiple subscriptions same publication?
thank you! :)
solution
thanks jeremy s. input , sleep after night shift i've figured out without autorun. here goes posterity:
template.runway_panel.oncreated(function(){ var self = this; self.subscribe('runway_status', this.data._id); });
should have tried getting sleep before trying again!
the problem this.data._id
in subscription, right scoped innermost function. want instance.data._id
(which nonreactive wouldn't need autorun
) or template.currentdata()
(which 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 in publication, should mark this.ready()
if this.userid
undefined
. that's not source of error.
Comments
Post a Comment