2015-09-14 87 views

回答

0

您可以在論壇主題meteor forum中閱讀,但現在在空間欄中是不可能的。

我們從用於鏈接方法和參數的新包開始,但尚未發佈。你可以做的是使用WITH元素像

反而是這樣的:

{{> someCoolHelper 
    someParam1='someVal1' 
    someParam2='someVal2' 
    someParam3='SomeVal3' 
    someParam4=someAnotherHelper 'value param to this helper' 
}} 

可以通過管理:

{{#with someAnotherHelper 'value param to this helper' }} 
    {{> someCoolHelper 
    someParam1='someVal1' 
    someParam2='someVal2' 
    someParam3='SomeVal3' 
    someParam4=this 
    }} 
{{/with}} 

我不喜歡它,但有時需要

Tom

PS:或者放下Spacebars並使用React - 你贏了'那裏有這樣的限制。

+0

謝謝,但我的項目中有一點點另一種情況..只有在「#with」條件存在某些值的情況下,您的變體才能使用此代碼塊。在我的情況下,由另一個幫助器返回的值可以是空的(數組長度爲零,例如false) –

+0

它不會變好,但您可以在外面使用{{if}}語句,以確保#將得到一個值,否則進入{{else}}語句。對不起,但那是空間條。 –

+0

'#with'現在被deprecied,因爲它更新上下文..使用'#let'現在 – Arthur

0

佔位符的解決方案,直到模板的子表達式Spacebars都可以是創建一個幫手JS返回適當值:爲你解答

HTML

{{> myTemplate param1="A" param2=param2}} 

JS

function someOtherHelper(param){ 
    console.log(param); 
} 

Template.registerHelper("someOtherHelper", someOtherHelper); 

Template.myTemplate.helpers({ 
    param2: function(){ 
    return someOtherHelper("B"); 
    } 
}); 
+0

是啊,謝謝:)我已經在我的代碼中實現了這個 –

+0

正如我理解你的問題,你正在尋找一個(動態)這個解決方案主要是在模板源代碼中完成的,而不是用'return someOtherHelper(「B」)''等特殊調用來編寫大量包裝函數。正確? –

+0

是的,你是對的 –

相關問題