如何在Yii的下拉列表中选择默认选项?然后当用户进入我的视图时,数据会自动显示?例如,我通过一月,二月等操作传递了几个月,我希望预先选择当前月份,当用户进入我的视图时,他应该看到来自本月?我想我必须使用javascript,但我的语法有问题,因为我对此很新。 这是我的观点:
<?php
?>
<div class="panel panel-primary">
<div class="panel-heading">
<?php
echo $schoolclass->description;
?>
</div>
</div>
<div class="panel panel-default">
<div class="panel-body">
<?php
$presentsData = CHtml::listData($presentmonths, 'presentmonth','presentmonth');
echo CHtml::dropDownList('presentmonthlist', 'presentmonth', $presentsData,
array(
'ajax'=>array('type'=>'POST',
'url'=>Yii::app()->createUrl('present/viewmonthlypresents',array('id'=>$schoolclass->schoolclassid)),
'update'=>'#mypresents',
'data'=>array('presentmonth'=>'js:this.value')
)
));
?>
</div>
</div>
<div id="mypresents">
</div>
<div class="panel panel-default">
<div class="panel-body">
<?php echo CHtml::button(Yii::t('default' ,'Submit Presents'), array(
'submit'=>array('create', 'id'=>$schoolclass->schoolclassid)
)
);
?>
</div>
</div>
答案 0 :(得分:0)
您可以像这样设置默认选择的选项,例如我使用的是&#39; 1月&#39;
echo CHtml::dropDownList('presentmonthlist', 'January', $presentsData,
array(
'ajax'=>array('type'=>'POST',
'url'=>Yii::app()->createUrl('present/viewmonthlypresents',array('id'=>$schoolclass->schoolclassid)),
'update'=>'#mypresents',
'data'=>array('presentmonth'=>'js:this.value')
)
));