[英]Yii: How to set dropDownList 'options' from array
I am using Yii 1.1.17. 我正在使用Yii 1.1.17。 I would like to know how to add disabled option to the dropdown list from array.
我想知道如何将禁用选项添加到数组的下拉列表中。 I know the way how to add options one by one
我知道如何逐个添加选项
echo CHtml::tag('td', array('class' => 'row'),
CHtml::dropDownList(
'TicketTypeAttribute['.$attr->ID.'][C_FTYPE]',
$attr->C_FTYPE,
TicketTypeAttribute::itemAlias('C_FTYPE'),
[
'options' => [
'INT' => ['disabled' => 'disabled']
],
'style' => 'width: 97%;',
'class' => 'ftype'
]
)
);
but is there a way to add it from array? 但是有没有办法从数组中添加它?
if($attr->C_FTYPE == 'DATETIME') {
$disallow = ['DECIMAL', 'INT', 'BOOLEAN', 'ENUM', 'BROKER_ID_BASE', 'BROKER_ID_ORG'];
} else {
$disallow = ['INT', 'BOOLEAN', 'DECIMAL', 'DATETIME', 'ENUM', 'BROKER_ID_BASE', 'BROKER_ID_ORG'];
}
Something like 就像是
echo CHtml::tag('td', array('class' => 'row'),
CHtml::dropDownList(
'TicketTypeAttribute['.$attr->ID.'][C_FTYPE]',
$attr->C_FTYPE,
TicketTypeAttribute::itemAlias('C_FTYPE'),
[
'options' => [
$disallow => ['disabled' => 'disabled']
],
'style' => 'width: 97%;',
'class' => 'ftype'
]
)
);
Easy enough to build the array yourself 很容易自己构建阵列
$disallowed_options = [];
foreach($disallow as $option_key){
$disallowed_options[$option_key] = ['disabled'=>'disabled'];
}
Then in your config 然后在你的配置中
'options'=> $disallowed_options,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.