简体   繁体   English

Meteor:将 onCreated 回调应用于所有模板

[英]Meteor: Applying the onCreated callback to all templates

I want to run some code on the onCreated event in meteor in every template.我想在每个模板中的流星中的 onCreated 事件上运行一些代码。

I know meteor allows helpers to apply to all templates:我知道meteor 允许助手应用于所有模板:

Template.registerHelper("example", function() {
  // do something
});

But is it possible to register a function that will apply to every onCreated event?但是是否可以注册一个适用于每个 onCreated 事件的函数?

You need to use a package like template-extension :您需要使用像template-extension这样的包:

meteor add aldeed:template-extension

Then you can do this :那么你可以做这个

Template.onCreated(function () {
  // do something
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM