douan1893 2014-01-09 08:27
浏览 39
已采纳

Yii依赖dropDownMenu与变量更新目标

I'm using standard Yii dependent dropDownMenu (something similar to this). The logic is that current dropDown will define which element (next dropDown) will be updated with controller action.

echo CHtml::dropDownList('level_1', '', $arrayWithValues, aaray(
  'ajax'=>array(
    'type'=>'POST',
    'url'=>Ccontroller::createUrl('myActionName'),
    'update'=>'#level_2'
)));

My question is how can I change the update value after the action is executed? i.e the action find out that we need to populate DropDown Level_3 instead of Level_2.

  • 写回答

1条回答 默认 最新

  • douni1396 2014-01-09 10:19
    关注
    echo CHtml::dropDownList('level_1', '', $arrayWithValues, aaray(
      'ajax'=>array(
        'type'=>'POST',
        'dataType' => 'json',
        'data'=>array('selected'=>'js:this.value'),,
        'url'=>Ccontroller::createUrl('myActionName'),
        'success'=>'js:function(data){
           if (data.update==2){
              $("#level_2").empty(); 
              $("#level_2").append(data.items);
           }
           if (data.update==3){
              $("#level_3").empty(); 
              $("#level_3").append(data.items);
           }
        }'
    )));
    

    In your controller you'll have selected value as $_POST['selected'].

    public function actionmyaActionName()
    {
        ....
        do what you need here
        $items.=CHtml::tag('option', array('value'=>$value),CHtml::encode($state),true);
    
        ....
        echo CJSON::encode(array(
        'update'=>$update,
        'items'=>$items
        ));
        Yii::app()->end();
    }
    

    Form your options, define what to update.

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

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效