yii2如何添加额外的属性到dropDownList()元素? [英] yii2 how to add additional attributes to dropDownList() elements?
本文介绍了yii2如何添加额外的属性到dropDownList()元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该怎么办?添加选项到field() - > dropDownList()只会添加列表元素容器的选项。
解决方案
尝试选项
echo $ form-> field($ model,'name') - > dropDownList($ listData,
['options'=> ['class'=>'yourClass',
'style'=>'yourStyle',
'yourAtt'=>'yourattribute']]);
或尝试
code> echo $ form-> field($ model,'name') - > dropDownList($ listData,
['data-target'=>'yourValue',
' data-toggle'=>'your2value']);
可以使用的项目
echo $ form-> field($ model,'name') - > dropDownList($ listData,
['options'=> [
'value1' => ['data-target'=>'yourAtt']]);
The question is simple. I want to add different data-attributes to each selection option so that Bootstrap will load different data according to which option was selected.
How should I go with it? Adding options to field()->dropDownList() will only add the options to list elements container.
解决方案
Try with options
echo $form->field($model, 'name')->dropDownList( $listData,
['options'=>['class' => 'yourClass',
'style' => 'yourStyle',
'yourAtt'=> 'yourattribute']]);
or try
echo $form->field($model, 'name')->dropDownList( $listData,
['data-target'=> 'yourValue',
'data-toggle' => ' your2value']);
for items you can use
echo $form->field($model, 'name')->dropDownList( $listData,
['options'=>[
'value1' => ['data-target' => 'yourAtt']]);,
这篇关于yii2如何添加额外的属性到dropDownList()元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文