我无法访问 jQuery 中的集合类型单选按钮的值
I can't access of Collection Type Radio Button's values in jQuery
Symfony 4 中的一种基本表单类型,具有 "simple fields"(如 TextType..)和一个 CollectionType。
如何访问 jQuery 中的集合类型单选按钮的值?
要获得 "simple field" 的值,我在 jQuery:
中执行此操作
$('#divfield').click( function() { ... } );
没问题
但对于 collectionType 中的字段也是如此:
$('#divInCollectionType').click( function() { ... } );
不可能,我不能 select 数据原型中的任何 div 或 class....
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']
))
例如,我只想在 radioButton 组更改时动态显示选中类别的名称...这很简单,但我不知道为什么使用 collectionType 它不起作用!
由于在显示表单时您的集合中没有元素,因此您无法直接从集合原型中定位 div。我建议你尝试类似的东西
$(document).on('click', '#divInCollectionType', function() {...})
Symfony 4 中的一种基本表单类型,具有 "simple fields"(如 TextType..)和一个 CollectionType。
如何访问 jQuery 中的集合类型单选按钮的值?
要获得 "simple field" 的值,我在 jQuery:
中执行此操作$('#divfield').click( function() { ... } );
没问题
但对于 collectionType 中的字段也是如此:
$('#divInCollectionType').click( function() { ... } );
不可能,我不能 select 数据原型中的任何 div 或 class....
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']
))
例如,我只想在 radioButton 组更改时动态显示选中类别的名称...这很简单,但我不知道为什么使用 collectionType 它不起作用!
由于在显示表单时您的集合中没有元素,因此您无法直接从集合原型中定位 div。我建议你尝试类似的东西
$(document).on('click', '#divInCollectionType', function() {...})