Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms Symfony2/细枝问题渲染集合删除\u btn_Forms_Symfony_Twig - Fatal编程技术网

Forms Symfony2/细枝问题渲染集合删除\u btn

Forms Symfony2/细枝问题渲染集合删除\u btn,forms,symfony,twig,Forms,Symfony,Twig,我们正试图直接从操作模板中以不同的方式呈现表单集合页面 我们遇到的问题是无法呈现小部件\u remobe\u btn按钮。例如,如果我们尝试{{form_widget(entity.name)}}我们就会得到名称。但是在这种情况下,我们没有收到我们期望的按钮{{form\u widget(entity.vars.widget\u remove\u btn)} 如果我们添加{form_rest(entity)}(以及从每个集合项打印每行的foreach中添加),则“移除”按钮将从表单下方移除,但不

我们正试图直接从操作模板中以不同的方式呈现表单集合页面

我们遇到的问题是无法呈现小部件\u remobe\u btn按钮。例如,如果我们尝试
{{form_widget(entity.name)}}
我们就会得到名称。但是在这种情况下,我们没有收到我们期望的按钮
{{form\u widget(entity.vars.widget\u remove\u btn)}

如果我们添加
{form_rest(entity)}
(以及从每个集合项打印每行的foreach中添加),则“移除”按钮将从表单下方移除,但不会呈现在form_小部件标记所在的位置

{{ form_start(form) }}
    {# render the task's only field: description #}

    <h3>Tags</h3>
        {# iterate over each existing tag and render its only field: name #}
        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <th>Name</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
            {% for entity in form.collection %}
                {{ form_start(entity) }}
                    <tr>
                        <td>{{ form_widget(entity.name) }}</td>
                        <td>{{ form_widget(entity.vars.widget_remove_btn) }}</td>
                    </tr>
                {{ form_end(entity) }}
            {% endfor %}
            <tbody>
        </table>
{{ form_end(form) }}
{{form_start(form)}
{#呈现任务的唯一字段:description}
标签
{#迭代每个现有标记并呈现其唯一字段:name#}
名称
行动
{form.collection%中实体的%s}
{{form_start(entity)}
{{form_小部件(entity.name)}
{{form_widget(entity.vars.widget_remove_btn)}
{{form_end(entity)}}
{%endfor%}
{{form_end(form)}}

为了防止它有用,我们正在使用MopaBootstrapBundle

我们通过使用
form\u row(entity)
而不是
row\u rest()
row\u widget()
,使它工作起来就像
form\u rest()
应该的那样;这是通过输出按钮实现的

以下是最终代码:

{{ form_start(form) }}

    <h2>Form</h2>

        <table class="table table-bordered table-striped table-hover collection-table">
            <thead>
                <tr>
                    <th>Op</th>
                    <th>Operation</th>
                    <th>Tools</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
            {% for entity in form.entities %}
                <tr>
                    <td>{{ form_widget(entity.name) }}</td>
                    {{ form_rest(entity) }}
                </tr>
            {% endfor %}
            <tbody>
        </table>
    {{ form_rest(form) }}
{{ form_end(form) }}
$('.collection-table').on('click.collection.data-api', '[data-collection-remove-btn]', function (e) {
    var $btn = $(e.target);

    if (! $btn.hasClass('btn')) {
        $btn = $btn.closest('.btn');
    }

    $btn.closest('tr').remove();

    e.preventDefault();
});