yii multi&反向依赖下拉菜单

时间:2014-01-27 06:54:18

标签: ajax drop-down-menu yii

由于这是我的第一个问题,请告诉我,如果我错过任何事情......

我有3个依赖的下拉菜单..

第一个下拉列表是选择将自动更新第二个下拉菜单的表名,该菜单将根据所选的表名列出属性名称..这已成功实现..

在第二个下拉菜单中,选择属性名称后,用户需要点击提交按钮..提交时,它将更新第二个下拉菜单以排除先前选择的属性名称,并将选定的属性名称发送到第三个下拉菜单..

更新第二个下拉菜单以排除先前选择的属性已成功实施..

但更新第3个下拉菜单并不成功..

指导我在哪里失踪..我仍然是Yii的新人所以请耐心等待我ok = D

控制器上的代码:

public function actionLoadColumn()
{
    $getCol = array();
    $col = array();

    $getTblNm[] = $_POST['tableNm'];

    if(isset($_POST['columnDD'])){
        $getCol[]=$_POST['columnDD'];
    }

    foreach($getCol as $getColKey=>$getColVal){
        foreach($getColVal as $getColKey1=>$getColVal1){
            $col[]=$getColVal1;
        }
    }

    $getAttr = array();
    foreach($getTblNm as $tblKey=> $tbl){
        foreach( $tbl as $data){
            $model1 = new $data;
            $getColumn = $model1->attributes;

            foreach($getColumn as $key=>$val){
                $getAttr[]=$key;
            }

            $getAttr = array_combine($getAttr, $getAttr);       
            unset($getAttr['created_by'],$getAttr['created_at'],$getAttr['updated_by'],$getAttr['updated_at']);     

            foreach($col as $colKey=>$colVal){
                unset($getAttr[$colVal]);
            }
        }

    }
    //var_dump($getAttr);

    foreach($getAttr as $value=>$city_name)
        echo CHtml::tag('option', array('value'=>$value),CHtml::encode($city_name),true);

    var_dump($col);

    if(isset($_POST['columnDD'])){
        echo CHtml::dropDownList('selCol','', $col,//CHTML::listData($getTNm,'tableNm','tableNm'),   
            array(
                'multiple'=>'multiple',
                'size'=>15,
                //'prompt'=>'SELECT TABLES',
                'ajax' => array(
                    'type'=>'POST', 
                    //'url'=>CController::createUrl('loadcolumn'),
                    //'update'=>'#columnDD', 
                    //'data'=>array('tableNm'=>'js:this.value'),
                )   
            )
        ); 
    }



    //foreach($col as $cVal=>$cKey)
    //  echo CHtml::tag('option', array('value'=>$cVal, 'update'=>'selCol'),CHtml::encode($cKey),true);



}
视图上的

代码:

<div class="form">
    <?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'base-company-reg-form',
        'enableAjaxValidation'=>false,
    )); 

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx----START----xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
    echo '<table><tr><td>1. Select tables</td><td></td><td>2. Select columns</td><td></td><td>3. Arrange columns</td></tr><tr><td>';

    echo CHtml::dropDownList('tableNm[]','', $getTNm,//CHTML::listData($getTNm,'tableNm','tableNm'),     
        array(
            'multiple'=>'multiple',
            'size'=>15,
            //'prompt'=>'SELECT TABLES',
            'ajax' => array(
                'type'=>'POST', 
                'url'=>CController::createUrl('loadcolumn'),
                'update'=>'#columnDD', 
                //'data'=>array('tableNm'=>'js:this.value'),
            )   
        )
    ); 

    echo '</td><td>';

    echo'=';

    echo '</td><td>';

    echo CHtml::dropDownList('columnDD[]','', array(), array('multiple'=>'multiple', 'size'=>'15')); 

    echo '</td><td>';

    echo CHtml::ajaxSubmitButton('>>>',Yii::app()->createUrl('baseCentre/loadcolumn'),
        array(
            'type'=>'POST',
            'update'=>'#columnDD',
        )
    );

    echo '</td><td>';

    //echo CHtml::dropDownList('selCol[]','', array(), array('multiple'=>'multiple', 'size'=>'15')); 

    echo '</td></tr></table>';

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx----END----xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx  
    ?>

<?php
    $this->endWidget(); 
?>


</div>

0 个答案:

没有答案