时间:2021-07-01 10:21:17 帮助过:20人阅读
因功能需求,需要用到联动,特此记录分享
<div class="main-form"> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'cid')->dropDownList( \common\models\service\common\Category::getCateOptions(), [ 'prompt' => '请选择单位', 'onchange'=>' $.post("/carousel/main/cate?id='.'"+$(this).val(),function(data){ $("select#main-aid").html(data); });', ] )->hint('父级,必选') ?> <?= $form->field($model, 'aid')->dropDownList( \common\models\service\common\Category::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>"; } }
相关推荐:
Yii2使用dropdownlist实现地区三级联动功能的方法
dropdownlist之间的互相联动实现(显示与隐藏)_javascript技巧
以上就是yii如何实现dropDownList的联动事件(代码)的详细内容,更多请关注Gxl网其它相关文章!