zoukankan      html  css  js  c++  java
  • YII实现dropDownList 联动事件

    因功能需求,需要用到联动,特此记录分享

    一、视图中

    
    <div class="main-form">
    
        <?php $form = ActiveForm::begin(); ?>
    
    
        <?= $form->field($model, 'cid')->dropDownList(
            commonmodelsservicecommonCategory::getCateOptions(),
            [
                'prompt' => '请选择单位',
                'onchange'=>'
                    $.post("/carousel/main/cate?id='.'"+$(this).val(),function(data){
                        $("select#main-aid").html(data);
                    });',
            ]
        )->hint('父级,必选') ?>
        <?= $form->field($model, 'aid')->dropDownList( commonmodelsservicecommonCategory::getCateOptions(), ['prompt' => '请选择子级']) ?>
        <div class="form-group">
            <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
        </div>
    
        <?php ActiveForm::end(); ?>
    
    </div>
    
    

    二、控制器

    
    ublic function actionCate($id)
    {
        $departments = Category::find()
            ->where(['parent_id' => $id])
            ->asArray()
            ->all();
    
        if(!$departments){
            echo "<option value='" . 0 . "'>"  . "</option>";
        }
        foreach ($departments as $department) {
            echo "<option value='" . $department['id'] . "'>" . $department['name'] . "</option>";
        }
    }
    
    

    三、实现效果

    原文地址:https://segmentfault.com/a/1190000016371322

  • 相关阅读:
    [Linux]
    [.Net]
    [.Net]
    [Linux]
    [Google]
    面向对象的7个基本设计原则
    windows SDK中的wininet写http客户端
    C++ 用libcurl库进行http通讯网络编程
    感悟
    关于Windows高DPI的一些简单总结
  • 原文地址:https://www.cnblogs.com/lalalagq/p/9971418.html
Copyright © 2011-2022 走看看