简体   繁体   English

流星部署服务器上未定义的全局模板助手

[英]Global template helper undefined on meteor deploy server

I have a file with global function on my Meteor project: 我的Meteor项目中有一个具有全局功能的文件:

client/helpers.js client / helpers.js

console.log("INIT client helpers")

formatCurrency = function(number, currencyCode) { /* [...] */ }
formatPercentage = function(percent) { /* [...] */ }

Template.registerHelper('formatCurrency', formatCurrency)
Template.registerHelper('formatPercentage', formatPercentage)

I use direcly formatCurrency function on the client code, and Blaze view. 我在客户端代码和Blaze视图上直接使用formatCurrency函数。 But when I try to deploy on meteor server, I got Exception in template helper: ReferenceError: formatCurrency is not defined . 但是,当我尝试在流星服务器上进行部署时,模板帮助器中出现异常:ReferenceError:formatCurrency未定义 Views are on /client/views/{category}/{view_name}.html, so they are loaded after helper. 视图位于/client/views/{category}/{view_name}.html上,因此它们在帮助程序之后加载。

On my local server, when I reload the page I got the log on browser console, but not when I hit the prod server. 在我的本地服务器上,当我重新加载页面时,我在浏览器控制台上获得了日志,但是当我点击产品服务器时却没有。

Do someone know what's the difference ? 有人知道有什么区别吗?

-------------[ UPDATE ]------------- ------------- [ 更新 ] -------------

Look like the helpers file is just never called by Meteor. 看起来助手文件从未被Meteor调用。 If I didn't use any of their function on helper, and load the page it's work. 如果我没有在helper上使用它们的任何功能,然后加载该页面,则它正常工作。 But if I try to call a function (on console), I have a undefined error, event 2sec after all the page is ready. 但是,如果我尝试调用一个函数(在控制台上),则会出现undefined错误,所有页面就绪后会发生事件2秒。

I think your load order might be around the wrong way. 我认为您的加载顺序可能是错误的方式。 According to the docs: http://docs.meteor.com/#/full/structuringyourapp , the views will be loaded first because they have deeper paths (rule 4), which beats alphabetical order (rule 5). 根据文档: http : //docs.meteor.com/#/full/structuringyourapp ,将首先加载视图,因为它们具有更深的路径(规则4),比字母顺序更好(规则5)。

HTML template files are always loaded before everything else
Files beginning with main. are loaded last
Files inside any lib/ directory are loaded next
Files with deeper paths are loaded next
Files are then loaded in alphabetical order of the entire path

Try putting the global helpers into a "lib" directory (rule 3), such as "client/lib/helpers.js" 尝试将全局帮助程序放入“ lib”目录(规则3),例如“ client / lib / helpers.js”

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

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