我试图在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']
)
答案 0 :(得分:0)
'options' => [
'data-image' => yourValue
]
或
'options' => [
'data' => [
'image' => yourValue
]
]
答案 1 :(得分:0)
参考:\ 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);