![](/img/trans.png)
[英]How to create dynamically disable a single check box of checkboxlist in YII
[英]How to disable few check boxes in a CheckBoxList in Yii?
我在Yii应用程序中使用CHtml :: checkBoxList。 我需要根据一些标准禁用一些复选框。 我如何使用Yii本身来做到这一点?
下面是我的代码
echo CHtml::checkBoxList('sid','',$posts1, array('id'=>'1','template' => '{input}{label}</td></tr><tr><td width="10%" style="padding:0 0 10px 20px;" class="rbr">','checkAll' => 'All'));
这将生成一个类似于下图的表
我需要禁用与第一行相对应的复选框。 即,其行中带有4X-B的复选框。
在这方面的任何帮助将不胜感激。
使用CHtml类是不可能的。 您可以创建custom Html class
。 或使用foreach
生成html。
创建一个动作为
public function actionIndex() {
$model= new CActiveDataProvider('ModelClass');
$this->render('index',array('model' => $model));
}
在Index.php视图文件中
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model,
'columns' => array(
array(
'class' => 'CCheckBoxColumn',
'disabled' => '$data->last_column=="4X-B" ? true : false',
),
'country',
'last_column'
)
));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.