如果您不需要选择父级,则可以使用 optgroup 标签
<select>
<optgroup label="Category 1">
<option>Option 1...</option>
<option>Option 2...</option>
<option>Option 3...</option>
</optgroup>
<optgroup label="Category 2">
<option>Option 1...</option>
<option>Option 2...</option>
<option>Option 3...</option>
</optgroup>
</select>
编辑:
Symfony 2 支持带有数组的 optgroup 标签(未经测试,可能包含错误):
public function buildForm(FormBuilder $builder, array $options)
{
$category_choices = array(
array('Category 1' => array(
'1' => 'Option 1...',
'2' => 'Option 2...',
'3' => 'Option 3...'
)),
array('Category 2' => array(
'4' => 'Option 4...',
'5' => 'Option 5...'
))
);
$builder->add('category_list', 'choice', array(
'label' => 'Category',
'choices' => $category_choices
));
}