本来想去yiichina问的,但是上面很水,基本只有站长偶尔回复一下!
就是类似于城市三级联动那种,选中一级之后,在后一个下拉框列出下一级的分类,只是我是用于我的分类。其实用html+js+php我是可以弄出来的,只是这样会抛弃yii自带的表单生成方法,也会失去他的验证!
暂时先用自己会的方法弄了,如果有大神知道,再改成yii风格的~
回复内容: 本来想去yiichina问的,但是上面很水,基本只有站长偶尔回复一下!
就是类似于城市三级联动那种,选中一级之后,在后一个下拉框列出下一级的分类,只是我是用于我的分类。其实用html+js+php我是可以弄出来的,只是这样会抛弃yii自带的表单生成方法,也会失去他的验证!
暂时先用自己会的方法弄了,如果有大神知道,再改成yii风格的~
yii2本身没有联动效果插件,都是用其他类拼接起来的,不过你自己可以写插件。yii2的例子没有,之前写过yii1的联动效果。你不想失去本身的验证,只要input的name跟模型中的一样就行了。
//view dropdownlist($blog,'mid',chtml::listdata(metas::model()->parents(),'mid','name'), array ( 'class'=>'form-control', 'empty'=>array('0'=>'请选择类别'), 'onchange'=>'ajaxgetarea(this)')); ?> error($blog,'mid'); ?>
//jsyii::app()->clientscript->registerscript('metas','function ajaxgetarea(obj){ //请求地址 var link = '.yii::app()->createurl(/cms/metas/json).'; //请求数据 $.post( link, { parent : $(obj).val() }, function(data) { //清除子类的select $(obj).parent().nextall(div).each(function() { $(this).remove(); }); if (data != -1) { //构造子类select的html var select = null; // 此处注意添加onchange事件 select = 请选择类别; $.each(data, function(key, item) { select += +item.name+; }); select +=
; //插入到右侧,上一级 $(obj).parent().after(select); //触发下一个子类select的动态加载 //$(obj).next(select).trigger(change, function() { //ajaxgetarea($(this)); //}); //更新name的位置 $(obj).removeattr(id); $(obj).next(select).attr(id, articles_mid); $(obj).removeattr(name); $(obj).next(select).attr(name, articles[mid]); } }, json );}',cclientscript::pos_end);
http://www.cnsecer.com/7140.html 不要谢我