具有4下拉列表其工作像魅力除了當頁面被呈現在第一下拉列表是當我有從控制器傳遞這樣Yii的4 depedent下拉列表從控制器傳遞
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
)
);
}
預選值預選值顯示預選值。我已經用下面的代碼測試了第二個dropdownlist,但它並沒有觸發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>
我在哪裏弄錯了?
特拉維斯嗨,你能更具體和詳細。我有幾個dropDown列表,這就是爲什麼我有#Spares_bodyid在那裏將模型更改或選擇時,將呈現bodystyles。 – user2208410