Symfony 4中具有"简单字段"(如TextType..(和一个CollectionType的基本表单类型。
如何在 jQuery 中访问集合类型单选按钮的值?
为了获得"简单字段"的值,我在jQuery中这样做:
$('#divfield').click( function() { ... } );
好的,没问题
但与 collectionType 中的字段相同:
$('#divInCollectionType').click( function() { ... } );
不可能,我无法选择数据原型中的任何div 或类....
FormType "User":
->add('tel_contact')
->add('struct', CollectionType::class, array(
'entry_type' => StructureType::class,
'data_class' => null,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
))
FormType "StructureType":
->add('category', EntityType::class, array(
'class' => Category::class,
'choices' => ...,
'choice_label' => 'nom_cate',
'expanded' => true,
'choice_value' => null,
'attr' => ['class' => 'categories']
))
例如,我只想动态显示当单选按钮组更改时检查的类别的名称......这很容易,但我不知道为什么使用集合类型它不起作用!
由于显示窗体时集合中没有元素,因此无法直接定位集合原型中的div。我建议你尝试类似的东西 $(document).on('click', '#divInCollectionType', function() {...})