Search code examples
meteormeteoritemeteor-helper

Meteorjs - Passing data context to Template Rendered function?


I have these data context and I want to use JQuery to set the selected value in the tag based on the value.

I am having problem passing the return data from the helpers into the Template.Rendered function.

is there any way of doing that?

Helpers

Template.studentSetting.helpers({
  values: function(){
    return Basics.findOne({userId:Meteor.userId()});
  }
});

Rendered function

Template.studentSetting.rendered = function(){
 //I want to use the "values" helper data here and perform some jquery code based on that?? 
}

Solution

  • According to this post, I would advise doing what mpowaga suggests in the thread and just define the helper outside:

    var valuesFunc = function () {
      return Basics.findOne({userId:Meteor.userId()});
    };
    
    Template.studentSetting.helpers({
      values: valuesFunc
    });
    
    Template.studentSetting.onRendered(function(){
      var values = valuesFunc();
    });