Yii 1.1.3 设置依赖下拉菜单的选定值 [英] Yii 1.1.3 setting selected value of dependent dropdown

查看:22
本文介绍了Yii 1.1.3 设置依赖下拉菜单的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有 3 个从属下拉列表,用于创建实体.

I have 3 dependent dropdowns on my page for creation of entity.

    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());

现在我想在编辑时为他们提供选定的选项:我找到了如何提供选定的选项.我在这里找到了方法.第一个选择有这个代码:

Now I want to give them selected options while edit: I found how to give selected options. I found here how to do it. First select has this code:

<select name="OpenLessons[Building]" id="OpenLessons_Building">
<option value="19">primary school</option>
<option value="6">high school</option>
</select>

所以,我想将它的值设置为高中.

So, I want to set it's value to high school for example.

        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 帮助我设置了第一个下拉列表的值,但是还有两个依赖下拉列表,我遇到了问题.这是我的下一个问题

And chosen value while editing entity is always - primary school. What's wrong? UPDATE @Tristup helped me to set value of first dropdown, but there are two more dependent dropdowns and I have problems with it. Here is my next question

推荐答案

dropDownList 的第二个参数是默认选择.

The second parameter for the dropDownList is the default selection.

Chtml::dropDownList($name, $select, $data)

示例:

$options = array ('0' => 'Select A Value', '1' => 'Tristup','2'=>'Sergey');
echo CHtml::dropDownList('mySelect', '0', $options);

这里的0"是默认选择的值.

here '0' is the value for the default selection.

希望这对你有用.

这篇关于Yii 1.1.3 设置依赖下拉菜单的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆