I'm trying to render a Template via Blaze. So normally I call
Blaze.render(Template.xxx,$("#parentnode")[0]);
which works fine.
Now I want to differentiate in the Template xxx who rendered it. So I want to pass a variable to the Template which I can use to decide who it was. I tried
Blaze.renderWithData(Template.xxx,{test:"value"},$("#parentnode")[0]);
And then tried to access the Data in
Template.xxx.onRendered(function(){console.log(this.test)});
which logged "this.test is not defined blabla". How can I pass data correctly and access it?
Thanks for your answers and have a good one!
According to meteor docs it is not possible to access context object in onRendered
callback. The this
keyword refers to the template instance and does not contain any stateful data. What you can do is to render the data properties inside DOM nodes (in hidden elements if you don't want to display them). You can access the DOM from onRendered
function.
Template.currentData() is available when the template is rendered so try using Template.currentData() instead of this and it should work:
Template.xxx.rendered = function() {
var _this = Template.currentData();
console.log(_this.test)
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.