從流星0.9.4開始,定義模板。 MyTemplate。 MyHelperFunction()不再有效。從模板的上下文中調用另一個助手的助手(流星0.9.4)
我們不推薦使用Template.someTemplate.myHelper = ...語法來支持Template.someTemplate.helpers(...)。使用較舊的語法仍然有效,但會向控制檯輸出棄用警告。
這對我來說似乎很好,因爲它(至少)會保存一些錯誤輸入和重複的文本。不過,我很快就發現,我構建Meteor應用程序的方式依賴於這個新版本已棄用的能力。在我的應用程序中,我一直使用舊的語法定義助手/函數,然後從其他助手調用這些方法。我發現它幫助我保持代碼清潔和一致。
例如,我可能有這樣的控制:
//Common Method
Template.myTemplate.doCommonThing = function()
{
/* Commonly used method is defined here */
}
//Other Methods
Template.myTemplate.otherThing1 = function()
{
/* Do proprietary thing here */
Template.myTemplate.doCommonThing();
}
Template.myTemplate.otherThing2 = function()
{
/* Do proprietary thing here */
Template.myTemplate.doCommonThing();
}
但這似乎並沒有提供新方法流星建議(這讓我覺得我錯了一直以來)。我的問題是,在模板的助手之間共享通用模板特定邏輯的首選方式是什麼?
我意識到這仍然是一個有效的問題,因爲測試平臺最好能夠調用模板助手。否則,你最終會不必要地重寫你的應用程序... – MrMowgli 2015-02-16 02:40:26
你可能會覺得這個答案有用:https://stackoverflow.com/questions/27755891/meteor-what-is-spacebars-kw-hash-object#answer-27756461 – 2015-09-25 16:25:29