Yii 1.1.3 设置依赖下拉列表的选择值
Yii 1.1.3 setting selected value of dependent dropdown
我的页面上有 3 个用于创建实体的相关下拉菜单。
echo CHtml::dropDownList('OpenLessons[Building]', '', $buildingList,array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/floorList'), //url to call.
'update'=>'#OpenLessons_Floor', //selector to update
)));
echo CHtml::dropDownList('OpenLessons[Floor]','', array(),array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/roomList'),
'update'=>'#OpenLessons_Class_ID',
)));
echo CHtml::dropDownList('OpenLessons[Class_ID]',$model->Class_ID, array());
现在我想在编辑时给他们 selected 选项:
我找到了如何提供 selected 选项。我找到了 here 如何去做。
首先 select 有这个代码:
<select name="OpenLessons[Building]" id="OpenLessons_Building">
<option value="19">primary school</option>
<option value="6">high school</option>
</select>
所以,我想将它的值设置为高中。
echo CHtml::dropDownList('OpenLessons[Building]', '', $buildingList,array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/floorList'),
'update'=>'#OpenLessons_Floor',
'options' => array('High school'=>array('selected'=>true)),
//Also tried this 'options' => array('6'=>array('selected'=>true)),
)));
编辑实体时选择的值始终是 - 小学。怎么了?
更新
@Tristup 帮助我设置了第一个下拉菜单的值,但是还有两个依赖下拉菜单,我遇到了问题。
这是我的 next question
dropDownList 的第二个参数是默认选择。
Chtml::dropDownList($name, $select, $data)
示例:
$options = array ('0' => 'Select A Value', '1' => 'Tristup','2'=>'Sergey');
echo CHtml::dropDownList('mySelect', '0', $options);
此处“0”是默认选择的值。
希望这对你有用。
我的页面上有 3 个用于创建实体的相关下拉菜单。
echo CHtml::dropDownList('OpenLessons[Building]', '', $buildingList,array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/floorList'), //url to call.
'update'=>'#OpenLessons_Floor', //selector to update
)));
echo CHtml::dropDownList('OpenLessons[Floor]','', array(),array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/roomList'),
'update'=>'#OpenLessons_Class_ID',
)));
echo CHtml::dropDownList('OpenLessons[Class_ID]',$model->Class_ID, array());
现在我想在编辑时给他们 selected 选项: 我找到了如何提供 selected 选项。我找到了 here 如何去做。 首先 select 有这个代码:
<select name="OpenLessons[Building]" id="OpenLessons_Building">
<option value="19">primary school</option>
<option value="6">high school</option>
</select>
所以,我想将它的值设置为高中。
echo CHtml::dropDownList('OpenLessons[Building]', '', $buildingList,array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('ajax/floorList'),
'update'=>'#OpenLessons_Floor',
'options' => array('High school'=>array('selected'=>true)),
//Also tried this 'options' => array('6'=>array('selected'=>true)),
)));
编辑实体时选择的值始终是 - 小学。怎么了? 更新 @Tristup 帮助我设置了第一个下拉菜单的值,但是还有两个依赖下拉菜单,我遇到了问题。 这是我的 next question
dropDownList 的第二个参数是默认选择。
Chtml::dropDownList($name, $select, $data)
示例:
$options = array ('0' => 'Select A Value', '1' => 'Tristup','2'=>'Sergey');
echo CHtml::dropDownList('mySelect', '0', $options);
此处“0”是默认选择的值。
希望这对你有用。