【问题标题】:In meteor, is there a onRendered function for all templates?在meteor中,所有模板都有onRendered函数吗?
【发布时间】:2016-03-25 15:38:59
【问题描述】:

在meteor中,所有模板都有onRendered函数吗?或者有没有简单的替代方案?

例子:

Template.allTemplates.onRendered(function(){/*doSomething()*/});

而不是:

Template.template0.onRendered(function(){/*doSomething()*/});
Template.template1.onRendered(function(){/*doSomething()*/});
Template.template2.onRendered(function(){/*doSomething()*/});

【问题讨论】:

    标签: javascript templates meteor


    【解决方案1】:

    似乎答案就在你面前:

    _.each(_.keys(Template), function(key) { 
         if (Template[key] instanceof Blaze.Template) { 
            console.log(key, "is the name of a template");
            Template[key].onRendered(myGlobalOnRenderFunction);
         }
    });
    

    虽然我不会推荐它。似乎很难预测在这种情况下会发生什么,因为这也会触发嵌套模板,因此您可能会收到比您希望的更多的对该处理程序的调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-05
      • 2016-10-06
      • 1970-01-01
      • 2016-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多