doucheng2053 2015-06-17 06:03
浏览 93
已采纳

Yii 1.1.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)),
            ))); 

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

  • 写回答

1条回答 默认 最新

  • dongshuo5101 2015-06-17 06:13
    关注

    The second parameter for the dropDownList is the default selection.

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

    Example :

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

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

    Hope this will work for you.

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog