YII依赖的下拉下拉在创建时工作良好,但在更新时,第一个下拉数据即将到来,但第二个下拉数据没有显示


<div class="row">
            <?php echo $form->labelEx($model,'ClassId'); ?>     
            <?php 
            $School=Yii::app()->session['Schoolid'];
            echo CHtml::activeDropDownList($model,'ClassId',CHtml::listData(Classdetails::model()->findAll(array("condition"=>"classid >0 and School_Id='$School' and Status=1","order"=>"classid")),'classid','classname'),
            array(
             'empty'=>'--Select a Class--',
             'ajax' => array(
             'type'=>'POST', //request type
             'url'=>CController::createUrl('Studentmarks/Dynamiccities'), //url to call.
             'data'=>array('Classid'=>'js: $(this).val()'),         
             'update'=>'#'.CHtml::activeId($model,'pid'),   
             )));
                 echo $form->error($model,'ClassId');
                echo $form->labelEx($model,'pid');
              echo CHtml::activeDropDownList($model,'pid', array(),array('prompt'=>'-- Select a Student --')); 
             echo $form->error($model,'pid');
                ?>      
            </div>

根据指定的代码,您显式地将第二个下拉框设置为空,这就是为什么它在更新视图中不起作用。

在更新模式下,只需在选择保存值的情况下用可能的值填充下拉框。

你可以这样做。

if($model->isNewRecord)
    echo CHtml::activeDropDownList($model,'pid', array(),array('prompt'=>'-- Select a Student --')); // create
else
    echo CHtml::activeDropDownList($model,'pid', $model->populateStudentsDate($model->ClassId));  // update

populateStudentsDate($model->ClassId)方法中,您需要过滤并显示每个班级选择的学生列表。

相关内容

最新更新