有 4 个像魅力一样工作的下拉列表,除非我像这样从控制器传递了预选值
public function actionBodyTrim(){
$trim = new CarTrim;
$spares = new Spares;
$spares->makeid = $_REQUEST['mid'];
$spares->modelid = $_REQUEST['moid'];
$spares->bodyid = $_REQUEST['bid'];
$spares->trimid = $_REQUEST['tid'];
$this->render('bodytrim', array(
'trim'=>$trim,
'spares'=>$spares
)
);
}
呈现页面时,第一个下拉列表显示预选值。我已经使用下面的代码测试了第二个下拉列表,但它不会触发 Ajax 调用。结果如下所示
<div class="span5 leftpull">
<div class="row">
<div class="width125"><?php echo $form->labelEx($model,'makeid'); ?></div>
<div class="widthtxt"><?php echo $form->dropDownList($model,'makeid', CHtml::listData(Makes::model()->findAll(array('order' => 'makename ASC')), 'makeid', 'makename'),
array('prompt'=>'Select Makes',
'ajax'=>array('url'=>CController::createUrl('CarModels'),
'beforeSend' => 'function(){$("#carmodels").addClass("loading");}',
'complete' => 'function(){$("#carmodels").removeClass("loading");}',
'type' =>'POST',
'update'=>'#'. CHtml::activeId($model, 'modelid'),
array('class'=>'ajaxlink'),
))); ?>
<?php echo $form->error($model,'makeid'); ?>
</div>
</div>
<div class="row" id="carmodels">
<div class="width125"><?php echo $form->labelEx($model,'modelid'); ?></div>
<div class="widthtxt"><?php echo $form->dropDownList($model, 'modelid', empty($model->modelid) ? array('prompt' => 'Select the country first') :
array('ajax'=>array('type'=>'POST',
'url'=>CController::createUrl('BodyType'),
'update'=>'#'. CHtml::activeId($model, 'bodyid'),
'prompt'=>'Models',
array('class'=>'ajaxlink'),
)));
?>
<?php echo $form->error($model,'modelid'); ?>
</div>
</div>
Ajax 的 HMTL 代码未按要求触发。
<div class="row" id="carmodels">
<div class="width125"><label for="Spares_modelid" class="required">Model <span class="required">*</span></label></div>
<div class="widthtxt"><select name="Spares[modelid]" id="Spares_modelid">
<optgroup label="ajax">
<option value="type">POST</option>
<option value="url">/spareparts/index.php?r=spares/parts/BodyType</option>
<option value="update">#Spares_bodyid</option>
<option value="prompt">Models</option>
<optgroup label="0">
<option value="class">ajaxlink</option>
</optgroup>
</optgroup>
</select> </div>
</div>
我在哪里弄错了?