我想知道如何在 Zend 2 中为 select 的选项添加一些属性。我的表单元素如下所示:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'brand_name',
'options' => array(
'label' => 'Choose brand',
'value_options' => $this->getBrands(),
),
));
所以它的填充选择看起来与此类似:
<select name="brand_name"><option value="1">aaaa</option></select>
但我想实现这样的目标:
<select name="brand_name"><option value="1" class="test">aaaa</option></select>
并且类应该不同,取决于特定的选项。是否可以?我为什么要尝试这个?我需要添加 jquery 插件 - 链接它需要选项的类。
最佳答案
我找到了一个解决方案,parent select value_options 的数组应该是这样的:
foreach ($data as $item) {
$models[] = array(
'label' => $item->model_name,
'attributes' => array('class' => $item->id_brand_list),
'value' => $item->id);
}
关于php - Zend2 Form - 将属性设置为选择元素中的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22957184/