YII实现dropDownList 联动事件
因功能需求,需要用到联动,特此记录分享
一、视图中
<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>";
}
}
三、实现效果
原文地址:https://segmentfault.com/a/1190000016371322
YII实现dropDownList 联动事件的更多相关文章
- YII2 实现dropDownList 联动事件
一.视图中 <div class="main-form"> <?php $form = ActiveForm::begin(); ?> <?= $fo ...
- MVC编辑状态两个DropDownList联动
前几天使用jQuery在MVC应用程序中,实现了<jQuery实现两个DropDownList联动(MVC)>http://www.cnblogs.com/insus/p/3414480. ...
- GridView中两个DropDownList联动
GridView中两个DropDownList联动 http://www.cnblogs.com/qfb620/archive/2011/05/25/2057163.html Html: <as ...
- jQuery实现两个DropDownList联动(MVC)
近段时间原本是学习MVC的,谁知道把jQuery也学上了.而且觉得对jQuery更感兴趣,比如今早上有写了一个练习<jQuery实现DropDownList(MVC)>http://www ...
- ASP .NET DropDownList多级联动事件
思路 假如有三级省.市.区,先加载出所有省选择省之后,加载出该省所有市选择市之后,加载出该市所有区重新选择省,则清空市和区重新选择市,则清空区想好数据结构,不同的数据结构做法不同 例子 数据结构 pu ...
- Yii 控制dropdownlist / select 控件的宽度和 option 的宽度
默认情况下, option的宽度会由options中最宽的元素决定,并且同时决定着select控件的宽度 在Yii中,如果需要自定义select控件的宽度,可以用 htmlOptions定义,如下: ...
- Yii 2.0 中事件的使用
关于PHP的事件处理,参照 http://www.cnblogs.com/mafeifan/p/4322238.html http://www.cnblogs.com/mafeifan/p/43222 ...
- kendo grid dropdownlist 联动 cascading
之前是无法联动的 后来将html页面中的 //$('<input required data-text-field="CompanyName" data-value-fiel ...
- GridView中实现DropDownList联动
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
随机推荐
- Android 最新面试题
1. Intent的几种有关Activity启动的方式有哪些,你了解每一个含义吗? Intent的一些标记有FLAG_ACTIVITY_BROUGHT_TO_FRONT .FLAG_ACTIVITY_ ...
- Iterator - 迭代器模式
定义 提供一个方法顺序訪问一个聚合对象中个各个元素,而又不须要暴露该对象的内部结构. 案例 一个聚合对象.如一个列表List.应该提供一种方法来让别人能够訪问它的元素.而又不用暴露内部结构.迭代器模式 ...
- C/C++中字符串String及字符操作方法
本文总结C/C++中字符串操作方法,还在学习中,不定期更新. .. 字符串的输入方法 1.单个单词能够直接用std::cin,由于:std::cin读取并忽略开头全部的空白字符(如空格,换行符,制表符 ...
- Windows下Go语言 幽灵蛛的配置
这里是环境变量 目录结构 在这其中,我主要需要观察src
- oc18--self1
// // Iphone.h // day13 #import <Foundation/Foundation.h> typedef enum { kFlahlightStatusOpen, ...
- [转]详细解读TrueSkill 排名系统
概要 大多数竞技游戏都有一个评价玩家是否完成目标的度量指标,它是游戏的基础.对于包含两个或两个以上玩家(多玩家比赛)的比赛,常涉及到游戏玩家技能的排名方法.游戏鼓励玩家之间相互竞争,玩家不只要赢得单场 ...
- 0x56 状压DP
gan这两题怎么差不多 #include<cstdio> #include<iostream> #include<cstring> #include<cstd ...
- The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1.
C:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInferenc ...
- eclipse中打字中文突然变成繁体
eclipse中打字中文突然变成繁体 在用eclipse做android项目的时候,发现打出来的字全部是繁体,而且QQ等其他位置又是简体. 原因:eclipse的快捷点ctrl+alt+f(forma ...
- Node.js:REPL(交互式解释器)
ylbtech-Node.js:REPL(交互式解释器) 1.返回顶部 1. Node.js REPL(交互式解释器) Node.js REPL(Read Eval Print Loop:交互式解释器 ...