Template onload event for meteor.js

后端 未结 3 1039
囚心锁ツ
囚心锁ツ 2020-12-14 02:07

I know meteor exposes events such as \"click\", for DOM element but I\'m wondering if there\'s a load event that\'s fired when a template or partial is loaded? How would I a

3条回答
  •  时光取名叫无心
    2020-12-14 02:46

    I'd recommend this rather than the accepted answer, slightly less gross IMHO:

    
    
    Template.temp.aReactiveHelper = function() {
      var someValue = Session.get('someValue');
      invokeAfterLoad();
      return someValue;
    };
    
    var invokeAfterLoad = function () {
      Meteor.defer(function () {
         $('mydiv').doSomething();
      });
    };
    

    The assumption is that you want to invoke something after the template loads because it's reacting to a reactive object.

    The benefit here is you're not adding animation code to your template.

提交回复
热议问题