Meteor template helpers fire multiple times

泄露秘密 提交于 2019-12-25 05:28:05

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17349516/meteor-template-helpers-fire-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!