基本上,我使用Kartik Select2创建了一个下拉列表。
如果我有这样的数据:
<?php
$mapListNoEstimate = ArrayHelper::map($listNoEstimate, 'id', function ($model, $value) {
return $model['no_surat'] . ' - ' . $model['level'];
});
在Select2中:
echo $form->field($model, 'repair_estimate_id')->widget(Select2::className(), [
'data' => $mapListNoEstimate,
'theme' => Select2::THEME_CLASSIC,
'options' => [
'placeholder' => 'Select an estimate ...',
'options' => [
]
],
])
,我们如何添加一些数据属性?
就我而言,我想在每个选项中添加数据级别。
你知道,在遗产选择选项中,我们可以这样做:
<select>
<option value='$model["id"]' data-level= '$model["level"]'>
$model['no_surat'] . ' - ' . $model['level']
</option>
</select>
请告知。
答案 0 :(得分:0)
您可以在options
内设置options
。请参阅以下示例。
echo Select2::widget([
'name' => 'kv-type-01',
'data' => [1 => "First", 2 => "Second", 3 => "Third", 4 => "Fourth", 5 => "Fifth"],
'options' => [
'placeholder' => 'Select a type ...',
'options' => [
1 => ['data-level' => 'something 1'],
2 => ['data-level' => 'something 2'],
3 => ['data-level' => 'something 3'],
4 => ['data-level' => 'something 4'],
5 => ['data-level' => 'something 5'],
]
],
]);