y0227 2012-04-03 15:06:52 4137次浏览 4条回复 0 0 0

表单文件:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'caigou-form',
    'enableAjaxValidation'=>true,
)); ?>

<?php echo $form->errorSummary($model); ?>
<?php echo $form->dropDownList($model,'dcate_id',$model->provinceList,array(
    'empty'=>'-请选择-',
    'ajax'=>array(
        //'type'=>'POST',
        'url'=>Yii::app()->createUrl('caigou/dynamicCity'),
        'data'=>array('id'=>'js:this.value'),
        'update'=>'#Caigou_der',
    ),
)); ?>
<?php echo $form->dropDownList($model,'der',$model->getCityList($model->dcate_id),array('empty'=>'-请选择-')); //echo $model->dcate_id.'sfds';?>

控制器:

public function actionDynamicCity($pid)
{
    //$model = Category::model()->findAllByAttributes(array('parent_id'=>$pid));
    //$model = CHtml::listData($model, 'id', 'cat_name');
    $model = Category::model()->getCityList($pid);
    foreach($model as $value=>$name)
    {
        echo CHtml::tag('option',array('value'=>$value),CHtml::encode($name),true);
    }
}

model模型:

public function getProvinceList()
{
    $model = Category::model()->findAllByAttributes(array('parent_id'=>0));
    return CHtml::listData($model, 'id', 'cat_name');
}
	
public function getCityList($pid)
{
    $model = Category::model()->findAllByAttributes(array('parent_id'=>$pid));
    return CHtml::listData($model, 'id', 'cat_name');
}

点击第一个下拉框时,第二个没反应.是怎么回事啊???

<?php echo $form->dropDownList($model,'der',$model->getCityList('86'),array('empty'=>'-请选择-'));?>这样第二个下拉框就有值了,可能是值没传过了,不知道哪里出错了,知道的说声啊,纠结了好久了

您需要登录后才可以回复。登录 | 立即注册