2016-11-01 91 views
0

如何使這樣的具有自己獨特的類名在每個循環嫩枝for循環把每1元的新容器

{% for row in rows %} 
    {{ row.content }} 
{% endfor %} 


<div class="item1"> Item 1 </div> 
<div class="item2"> Item 2 </div> 
<div class="item3"> Item 3 </div> 
<div class="item4"> Item 4 </div> 

等我如何才能做到這一點,請幫助表示感謝。

或者是否有其他方法可以在for循環中單獨調用每個元素???

回答

2

您可以使用loop.index

{% for row in rows %} 

    <div class="item{{ loop.index }}">{{ row.content }}</div> 
{% endfor %} 
+0

太感謝你了......有沒有一種方法,我可以單獨使用和指數類似{{row.content [0]}}或者將數據內容{ {row.content.0}} –

+0

{{rows [0] .content}}應該有效。 – MilanG