為了實(shí)現(xiàn)所需的輸出,其中下拉列表中的每個(gè)項(xiàng)目都由一個(gè)具有指定標(biāo)簽、值和樣式的單個(gè)<option>
標(biāo)簽表示,您需要按照以下方式修改您的代碼:
在您的視圖文件中,更新customDropDown
函數(shù)調(diào)用以正確傳遞items數(shù)組:
<?= $form->customDropDown($dpForm, 'color', [ [ 'label' => 'red', 'value' => 'red', 'options' => [ 'style' => 'color: red' ] ], [ 'label' => 'blue', 'value' => 'blue', 'options' => [ 'style' => 'color: blue' ] ], ] ); ?>更新的方法:
public function customDropdown($model, $attribute, $items = [], $options = []) { $value = Html::getAttributeValue($model, $attribute); $field = $this->field($model, $attribute); $options['options'] = array_column($items, 'options'); $options['prompt'] = ''; return $this->staticOnly ? $field : $field->dropDownList(array_column($items, 'label', 'value'), $options); }在這個(gè)更新的版本中,我們直接將$options數(shù)組傳遞給
dropDownList
方法,并使用array_column
從$items數(shù)組中提取標(biāo)簽-值對(duì)微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)