2012-05-23 90 views
0

我有一個網頁表單頁面,可以通過點擊鏈接動態添加其他字段。這個頁面被分成了各種模板,特別是表單的每個字段都有它自己的模板。現在爲了完成這項工作,我必須複製和粘貼最終生成的html代碼並將其分配給操縱DOM,是否有一種方法可以讓Jquery重用我已經寫好的TWIG模板?如何使用jquery包含樹枝模板

對於我的情況爲例來看看:http://symfony.com/doc/master/cookbook/form/form_collections.html#allowing-new-tags-with-the-prototype

+0

其實我走了使用TWIG宏的道路,它更具可定製性,無論如何,渲染的html是默認的,你可以通過調用form_row()函數來看到。任何人都可以幫助我找到解決方案嗎? – linuxatico

回答

-1

我不知道我是否理解你。我在我的項目中有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, 
        ) 
      ) 
... 

而且在研究名單後,模板我有Add new與JS代碼

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表單按鈕。