Data not accessible in helper block in Meteor -


i have autopublish on.

template.play.helpers ({    title: function () {   wcount = workouts.find().count();   console.log(wcount);    } }); 

this gives me 0.

but if i'm in developer console of browser.

workouts.find().count() 24 

i have upgraded 0.8

if add waiton router behavior every other time load page.

router.map(function() { this.route('splash', {path: '/'}); this.route('play', {  path: '/play', template: 'play', waiton: function() {      return meteor.subscribe('workouts') } }); 

after @christian fritz seems problem not waiting on subscription , if helper doesn't return because undefined doesn't rerun when data loaded.

i have turned off autopublish. server/publications.js is:

meteor.publish('workouts', function() {    return workouts.find(); }); 

my router is:

router.configure({      layouttemplate: 'layout',      loadingtemplate: 'loading' });   router.map(function() {     this.route('splash', {path: '/'});     this.route('play', {     path: '/play',    template: 'play',    waiton: function() {       return meteor.subscribe('workouts')   }     }); }); 

in play.js

var workoutssubcription = meteor.subscribe('workouts'); console.log("workoutssubscription.ready() ",workoutssubcription.ready()); 

returns: workoutssubscription.ready() false

once or twice reruns when loaded true. shouldn't waiton mean doesn't run page until data there?

you want this:

var workoutssubcription = meteor.subscribe('workout_count');  template.play.helpers ({    title: function () {      if(workoutssubcription.ready()){        wcount = workouts.find().count();      }    } }); 

you need publish subscription on server well

meteor.publish("workout_count", function () {   return workouts.find(); }); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -