Yii2 在 DropDownList 选项中添加附加属性数据图像

Yii2 Add additional attribute data-image in DropDownList options

我试图在 dropdownList

的标签中添加属性 "data-image"="image" 路径

我想要这个:

<select class="custom-select custom-select-lg mb-3" id="msdrpdd20" tabindex="-1">

<option selected="">Select Fit</option>

<option id="Orders-fit_id" name="Orders[fit_id]" data-image="/w1/backend/web/uploads/fit_image/10/splash.png" value="10">Slim </option>

<option id="Orders-fit_id" name="Orders[fit_id]" data-image="/w1/backend/web/uploads/fit_image/11/encryption-key.jpg" value="11">test1</option>                        </select>

这是我的代码:

$listData=ArrayHelper::map($fit_list,'id','name');

                        echo $form->field($model, 'fit_id')->dropDownList(
                                $listData,

                                ['options'=>[
                                   'value1' => ['data-target' => 'yourAtt']]]
                                //['prompt'=>'Select Fit___ssss', 'class'=>'custom-select custom-select-lg mb-3'] 

                               )
'options' => [ 
    'data-image' => yourValue 
]

'options' => [ 
    'data' => [ 
        'image' => yourValue 
    ] 
]

参考:\yii\helpers\BaseHtml::renderSelectOptions()

$listData = $options = [];
$options['options' => []];

foreach($fit_list as $item) {
    $listData[$item['id']] = $item['name'];
    $options['options'][$item['id']] = ['data-image' => 'image url'];
}

echo $form->field($model, 'fit_id')->dropDownList($listData, $options);