2015-01-15 44 views
2

從父循環/每個獲取值時遇到問題。我怎樣才能做到這一點?彙編(模板):從嵌套的每個塊內獲取父值

我正在循環瀏覽一些問題,然後循環查看一些答案。在每一個答案,我想補充的問題ID ..

的JSON:

{ 
    "questions": [ 
     { 
      "id": 1, 
      "answers": [ 
       ... 
       ... 
       ... 
      ] 
     } 
    ] 

} 

而Assemble.io嵌套循環/每

{{#forEach questions}} 
    <h2>{{id}}</h2> 
    <ul> 
     {{#forEach this.answers}} 
      <li> 
       <input type="radio" name="{{id}}" id="{{id}}-{{index}}"/> 
      </li> 
     {{/forEach}} 
    </ul> 
{{/forEach}} 

你知道我怎麼能從父循環/每個?

預先感謝您... :-)

回答

1

在車把上,你可以使用parent accessor syntax ../

{{#forEach questions}} 
    <h2>{{id}}</h2> 
    <ul> 
     {{#forEach this.answers}} 
      <li> 
       <input type="radio" name="{{../id}}" id="{{../id}}-{{index}}"/> 
      </li> 
     {{/forEach}} 
    </ul> 
{{/forEach}} 
+0

太好了!簡直不敢相信我沒有發現。謝謝! –