流星模板助手多次触发 [英] Meteor template helpers fire multiple times

查看:109
本文介绍了流星模板助手多次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Template.templateName.helpers({
//其中一些代码如
myLove:function(){
console.log(Fired );
返回meteor.js;
}
});

像魅力一样......但是有一个巨大的问题......当我想要使用变量myLove在5倍的模板中(在不同的地方),当我检查控制台时它会多次触发,所以当我有数据库查询它运行多次什么是定义不好......如何解决它?



BTW:我使用模板的句柄。

解决方案

,代码将被执行多次,这是真的。



虽然使用mongodb游标调用是安全的,但Meteor会优化它并只调用一次相同的查询(在服务器上)和客户的所有呼叫(与minimongo)都很便宜。

Template.templateName.helpers({
  // SOME CODE HERE LIKE
  myLove: function() {
    console.log("Fired");
    return "meteor.js";
  }
});

What works like a charm... but with one huge problem... when i want to use variable "myLove" in template like 5times (in different places) when i check console it fires multiple times so when i have there database query it runs multipletimes what is definely not good... how to fix it?

BTW: i use handlebars for template.

解决方案

If you use this template in multiple places, the code will be executed multiple times, that's true.

Although, using mongodb cursors calls is safe, Meteor optimizes it and calls identical queries only once (on server) and all calls on client (with minimongo) are cheap.

这篇关于流星模板助手多次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆