A similar question here:
The difference between Template.instance () and this
To understand that:
In the template functions of the life cycle (onCreated, onRendered ...), this is equal to Template.instance() , so this.data same as Template.instance().data AT THAT TIME!
In a helper or event, this is the current data context .
So, pay attention to the important thing here: The data context may change over time if your data changes upstream:
If you transfer data to the template, the template will be resubmitted with the new data. New data = new data context.
So, if you do something like:
Template.example.onCreated(function() { this.data.myKey = "my example data set on template creation";
Well, this data can be in this (i.e. data context) in your helper ( this.myKey ), but only as long as the upstream data does not change.
As soon as the upstream data changes, this will become the new data context and will NOT contain your added data.
So in short:
If you need to add context to your template in onCreated or onRendered , make sure that you DO NOT bind it to the current data context, but to Template.instance ()
you should:
Template.example.onCreated(function() { this.myKey = "my example data set on template creation";
and you can access this data in the helper and events through
Template.instance().myKey