问题
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??
}
回答1:
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();
});
回答2:
You need to call your studentSettings
template with an argument like this:
{{> studentSettings inheritedValues=values}}
You can then access it into your Rendered
function like this:
Template.studentSetting.rendered = function(){
var values = this.data.inheritedValues;
console.table(values);
}
来源:https://stackoverflow.com/questions/31558725/meteorjs-passing-data-context-to-template-rendered-function