javascript - Using template load as trigger for server method Meteor js -


i may using totally incorrect approach problem , if please tell me

my meteor app collects emails address , emails them link download page token. download page iron router route , token id of item in collection. token checked prior use , download initiated [that part not written yet]. have route:

this.route('download', {   path: '/download/:_id',   template: 'capture_download',   waiton: function () {     return meteor.subscribe('captures');   },   data: function() { return captures.findone(this.params._id); } }); 

so need trigger call server method checking logic route loaded. , need id value make call. have this:

template.capture_download.rendered = function(template) {     meteor.call('claimdownload', this.data._id, function(err, result) {        // callback logic here     }); } 

what don't understand works. call happens id value correct. other times get:

exception deps afterflush function function: typeerror: cannot read property '_id' of null 

so i'm thinking either template event [rendered] wrong [i can't find in docs list of template events anywhere], or need wait valid this value, or approach totally wrong. how fix occasional lack of data in view when rendered?

use onbeforeaction within iron router route, rather rendered method in template:

this.route('download', {   path: '/download/:_id',   template: 'capture_download',   waiton: function () {     return meteor.subscribe('captures');   },   data: function() { return captures.findone(this.params._id); },   onbeforeaction: function() {     meteor.call('claimdownload', this.params._id, function(err, result) {        // callback logic here     });   } }); 

see https://github.com/eventedmind/iron-router/blob/dev/docs.md#before-and-after-hooks. “checking token prior use” sounds lot “checking user logged in” example in docs, solved onbeforeaction.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -