簡體   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