我在数据库中有五个数据条目,mapset`我在树枝上渲染:
{{ form_start(form) }}
{% for item in mapset %}
<tr>
<td>{{ item.name }}</td>
<td>{{ form_widget(form.sets) }}</td>
<td>{{ form_widget(form.options) }}</td>
<td>{{ form_widget(form.buttonSet) }}</td>
<td>{{ form_widget(form.buttonItem) }}</td>
</tr>
{% endfor %}
{{ form_end(form) }}
此表单应该总共显示20个输入,如下所示:
name1 [] [] [] []
name2 [] [] [] []
name3 [] [] [] []
name4 [] [] [] []
name5 [] [] [] []
但我的代码显示:
name1 [] [] [] []
name2
name3
name4
name5
我已经阅读了很多关于动态表单和表单集合的内容,但我不明白。
答案 0 :(得分:0)
{# src/AppBundle/Resources/views/Task/new.html.twig #}
{# ... #}
{{ form_start(form) }}
{# render the task's only field: description #}
{{ form_row(form.description) }}
<h3>Tags</h3>
<ul class="tags">
{# iterate over each existing tag and render its only field: name #}
{% for tag in form.tags %}
<li>{{ form_row(tag.name) }}</li>
{% endfor %}
</ul>
{{ form_end(form) }}
{# ... #}
http://symfony.com/doc/2.7/cookbook/form/form_collections.html