繁体   English   中英

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

[英]Global template helper undefined on meteor deploy server

我的Meteor项目中有一个具有全局功能的文件:

client / helpers.js

console.log("INIT client helpers")

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

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

我在客户端代码和Blaze视图上直接使用formatCurrency函数。 但是,当我尝试在流星服务器上进行部署时,模板帮助器中出现异常:ReferenceError:formatCurrency未定义 视图位于/client/views/{category}/{view_name}.html上,因此它们在帮助程序之后加载。

在我的本地服务器上,当我重新加载页面时,我在浏览器控制台上获得了日志,但是当我点击产品服务器时却没有。

有人知道有什么区别吗?

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

看起来助手文件从未被Meteor调用。 如果我没有在helper上使用它们的任何功能,然后加载该页面,则它正常工作。 但是,如果我尝试调用一个函数(在控制台上),则会出现undefined错误,所有页面就绪后会发生事件2秒。

我认为您的加载顺序可能是错误的方式。 根据文档: 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

尝试将全局帮助程序放入“ lib”目录(规则3),例如“ client / lib / helpers.js”

暂无
暂无

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

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