我正在使用循环生成<tr>
和<td>
标记。我想重复<tr>
元素,但div.border_box_main_01
正在重复。
我做错了什么?
{% if data.about.data.pricing is defined and data.about.data.pricing is not null %}
<div class="border_box_main_01" >
{% set curr= '' %}
{% set curr =data.currency %}
{% set comments_flag=0 %}
{% set reminder_flag=0 %}
{% set see_more= data.result|length %}
{% for key,value in data.result %}
{# set comments=value.metadata.comment #}
{% set metadata= value.metadata|length %}
{% set comments= value.metadata[0].comment|length %}
{% set comments_flag = comments_flag + value.metadata|length%}
{% if comments_flag > 7 and reminder_flag==0 and key!=1 %}
{% set reminder_flag=1 %}
{% set comments_flag=0 %}
{% set comments_flag = comments_flag + value.metadata|length %}
{% endif %}
<div class="datagrid23 {% if key > 1%}fee_hide{%endif%}" {% if key > 1%}style="display:none;"{%endif%}>
<table class="table">
{% if reminder_flag ==1 %}
{% endif %}
{% if reminder_flag ==1 %}
<tr>
<td>{{ value.type }}</td>
{% set metadatas= value.metadata %}
{% for key,value in metadatas %}
<td>{{ curr}}{{ value.amount }}</td></tr>
{% endfor %}
</table>
</div>
输出应如下:
<div class="border_box_main_01">
<h1>Fees</h1>
<hr class="counter_countdown">
<div class="datagrid23">
<table class="table">
<tbody>
<tr>
<td>Busines Ticket</td>
<td>Rs 500</td>
</tr>
<tr>
<td>General Public Ticket</td>
<td>Rs 500</td>
</tr>
<tr>
<td>General Public Tickets Adult</td>
<td>Rs 50</td>
</tr>
</tbody>
</table>
</div>
</div>
答案 0 :(得分:0)
您应该在编写标记之前移动for标记,以便将其写在每个iteraton上:
{% if data.about.data.pricing is defined and data.about.data.pricing is not null %}
<div class="border_box_main_01" >
{% set curr= '' %}
{% set curr =data.currency %}
{% set comments_flag=0 %}
{% set reminder_flag=0 %}
{% set see_more= data.result|length %}
{% for key,value in data.result %}
{# set comments=value.metadata.comment #}
{% set metadata= value.metadata|length %}
{% set comments= value.metadata[0].comment|length %}
{% set comments_flag = comments_flag + value.metadata|length%}
{% if comments_flag > 7 and reminder_flag==0 and key!=1 %}
{% set reminder_flag=1 %}
{% set comments_flag=0 %}
{% set comments_flag = comments_flag + value.metadata|length %}
{% endif %}
<div class="datagrid23 {% if key > 1%}fee_hide{%endif%}" {% if key > 1%}style="display:none;"{%endif%}>
<table class="table">
{% if reminder_flag ==1 %}
{% endif %}
{% if reminder_flag ==1 %}
{% for key,value in metadatas %}
<tr>
<td>{{ value.type }}</td>
{% set metadatas= value.metadata %}
<td>{{ curr}}{{ value.amount }}</td></tr>
{% endfor %}
</table>
</div>
答案 1 :(得分:0)
for循环中有错误。 相反,尝试这样的事情:
<div class="datagrid23 {% if key > 1 %}fee_hide{% endif %}" {% if key > 1 %}style="display:none;"{% endif %}>
<table class="table">
<tr>
<td>{{ value.type }}</td>
</tr>
{% set metadatas = value.metadata %}
{% for key,value in metadatas %}
<tr>
<td>{{ curr }}{{ value.amount }}</td>
</tr>
{% endfor %}
</table>
</div>