繁体   English   中英

如何使用jQuery包括树枝模板

[英]How to include twig templates using jquery

我有一个Web表单页面,可以通过单击链接来动态添加其他字段。 在此页面中,它分为多个模板,特别是表单的每个字段都有其自己的模板。 现在要进行这项工作,我必须复制并粘贴最终生成的html代码,然后将其分配给操作DOM,是否有办法让Jquery重用我已经编写的TWIG模板?

有关我的情况的示例,请查看: http : //symfony.com/doc/master/cookbook/form/form_collections.html#allowing-new-tags-with-the-prototype

我不知道我是否了解你。 我在我的项目中拥有Profile实体以及Study实体的集合。 ProfileType具有

public function buildForm(FormBuilder $builder, array $options)
{
    $builder
            ->add('studies', 'collection', array(
                'type' => new StudyType(),
                'allow_add' => true,
                'allow_delete' => true,
                'by_reference' => false,
                    )
            )
...

在研究列表之后的模板中,我使用JS代码Add new按钮

    var children, classParts, nr, proto;
    children = $('#profile_' + name).children();
    if (children.size()) {
        classParts = children.last().attr('class').split('_');
        nr = classParts.pop()*1 + 1;
    } else {
        nr = 0;
    }
    proto = $('#profile_' + name + '').data('prototype');
    proto = proto.replace(/\$\$name\$\$/g, nr);
    $('#profile_' + name + '').append(proto)

之所以可行,是因为在呈现的形式中,我具有新的Study形式的原型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM