Home>Article>Backend Development> How to implement the linkage event of dropDownList in Yii (code)

How to implement the linkage event of dropDownList in Yii (code)

不言
不言 Original
2018-09-13 17:24:49 1978browse

The content of this article is about how Yii implements the linkage event (code) of dropDownList. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Due to functional requirements, linkage needs to be used, hereby record and share

1. View

= $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' => '请选择子级']) ?>
= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>

2. Controller

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

3. Realize the effect

How to implement the linkage event of dropDownList in Yii (code)

Related recommendations:

Yii2 uses dropdownlist to realize the regional three-level linkage function

Realization of mutual linkage between dropdownlists (showing and hiding)_javascript skills

The above is the detailed content of How to implement the linkage event of dropDownList in Yii (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn