0

如何将获取的数据(在本例中为:)$arr返回到我的视图(我可以像在表格中显示一样对其进行操作)。如果我在通过 ajax 处理的控制器操作中有这个:

public function actionFetchregularload(){
            $criteria = new CDbCriteria;
            $criteria->limit = 15;
            $criteria->condition='semester = 2';
            $criteria->select = array('subjCode','subjDesc','lec','lab','units');
            $criteria->addSearchCondition('yrLvl', $_GET['yrlevel']);
            $data = CompeProspectusA::model()->findAll($criteria);
            $arr = array();
            foreach ($data as $item){
                    $arr[] = array(
                            'subjcode' => $item->subjCode,
                            'subjdesc' => $item->subjDesc,
                            'lab' => $item->lab,
                            'lec' => $item->lec,
                            'units' => $item->units,
                    );
            }
    }
4

1 回答 1

1

renderPartial()用你的桌子或其他东西做一个视图,然后actionFetchregularload()像这样使用:

$this->renderPartial('_table', array('arr'=>$arr), false, true);

在您的主视图中,您可以使用CHtml::ajaxLink选项(其中“#contentdiv”是表 div 的 id):

CHtml::ajaxLink(
        "Update table",
        Yii::app()->createUrl('controller/fetchregularload'),
        array(    //ajaxOptions
            'type' => 'POST',
            'beforeSend' => "function(request) {
                $('#contentdiv').addClass('loading');   //add .loading class while loading - you can add background image
            }",
            'success' => "function(data) {
                $('#contentdiv').removeClass('loading');
                document.getElementById('contentdiv').innerHTML=data;
            }",
        ),
        //htmlOptions
        array('href' => Yii::app()->createUrl('controller/fetchregularload')); 
    );
于 2012-10-01T08:02:58.627 回答