Template. $ (selector) doesn't work Meteor

I just found it to be a good pattern to restrict DOM searches to the current pattern instead document

, so I started replacing everything document.querySelector()

with template.find()

and jquery $(selector)

with template.$(selector)

. Inside events everything works fine, but then in this code ( onRendered

) it just doesn't work and I get: TypeError: undefined is not an object (evaluating 'template.$')

in the console:

Template.icons.onRendered(function () {
    template.$('.demo-default').tooltipster({
        offsetY: 2,
         theme: 'tooltipster-shadow'
    })
});

      

Does anyone know what's going on?

+3


source to share


1 answer


In response callbacks for lifecycle events such as onCreated

, onRendered

and onDestroyed

, the current template instance is bound to a keyword this

.

Just replace template

(which by the way is undefined in this context) with this

:



Template.icons.onRendered(function () {
  this.$('.demo-default').tooltipster({
    offsetY: 2,
    theme: 'tooltipster-shadow'
  })
});

      

+2


source







All Articles