2013-08-29 61 views
1
<script id="contact-row" type="text/x-handlebars-template" > 

    {{#each rows}} 
     <tr> 
      {{getInputField @index "country" country }} 

      {{#each contactData}} 
      {{getInputFieldForData @index "contractName" contractName }} 
      {{/each}} 
     </tr> 
    {{/each}} 

如何獲取Handlebars模板中父循環的索引?

我希望得到家長的指數在內#each循環。我試過../@index,但是這給出了錯誤。

+0

它給出了什麼錯誤?你是否迭代了一系列對象? –

回答

3

貌似一切都變了......

要得到一個孩子{{#each}}塊內的父{{#each}}塊的索引使用{{@../index}}語法。

{{#each foo}} 
    {{@index}}   // Parent Index Reference 
    {{someProperty}}  // Parent property 
    {{#each baz}} 
     {{@index}}  // Child Index Reference 
     {{@../index}} // Parent Index Reference <-- 
     {{someProperty}} // Child property 
    {{/each}} 
{{/each}} 

在接受答案的鏈接有解決方案,只需張貼細節,在這裏爲後人的緣故。

相關問題