"this" in template helpers and template callbacks
In Meteor, this
in template helpers is used differently in template callbacks such as created()
, rendered()
, and destroyed()
.
As already mentioned, templates have three callback functions that are fired in different states of the template:
created
: This fires when the template gets initiated but is not yet in the DOMrendered
: This fires when the template and all its sub templates are attached to the DOMdestroyed
: This fires when the template is removed from the DOM and before the instance of the template gets destroyed
In these callback functions, this
refers to the current template instance. The instance object can access the templates DOM and comes with the following methods:
this.$(selectorString)
: This method finds all elements that matchselectorString
and returns a jQuery object from those elements.this.findAll(selectorString)
: This method finds all elements that matchselectorString
, but returns the plain DOM elements.this.find(selectorString...