问题
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