今天,在二次开发,修改节目是否为推荐节目是,需要用到,下拉框,结果,实现了switch按钮,上源码:
'model'=>$model,
'condensed'=>false,
'hover'=>true,
'mode'=> Yii::$app->request->get('edit') =='t'? DetailView::MODE_EDIT: DetailView::MODE_VIEW,
'panel'=> [
'heading'=>$this->title,
'type'=> DetailView::TYPE_INFO,
],
'attributes'=> [
'liveid',
//图片
[
'attribute'=>'imgurl',
'label'=>'图片地址:',
'format'=> ['raw'],
'value'=> Html::img($model->imgurl, ['width'=>'100','height'=>'100',]),
'type'=> DetailView::INPUT_FILEINPUT
],
//下拉框
[
'label'=>'是否推荐:',
'attribute'=>'is_recommend',
'value'=> Livepreview::isRecommend($model->is_recommend),
'type'=>DetailView::INPUT_SWITCH, //核心代码
'widgetOptions'=> [
'pluginOptions'=> [
'onText'=>'Yes',
'offText'=>'No',
]
],
],
],
'deleteOptions'=> [
'url'=> ['delete','id'=>$model->id],
],
'enableEditMode'=>true,
])?>
model方法:
public static functionisRecommend($satus){
$array= ['0'=>'否','1'=>'是'];
if(array_key_exists($satus,$array)){
return$array[$satus];
}
return false;
}
实现下拉框,需要修改两行代码:
'type'=>DetailView::INPUT_DROPDOWN_LIST,
'items'=>[0=>'否',1=>'是'],
参考地址:http://demos.krajee.com/detail-view