我正在使用Yii 1.1.17。我想知道如何将禁用选项添加到数组的下拉列表中。我知道如何逐个添加选项
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'
]
)
);
但有没有办法从数组添加它?
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'];
}
像
这样的东西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'
]
)
);
答案 0 :(得分:1)
很容易自己构建阵列
$disallowed_options = [];
foreach($disallow as $option_key){
$disallowed_options[$option_key] = ['disabled'=>'disabled'];
}
然后在你的配置
'options'=> $disallowed_options,