二级联动
例子:
<div class="title"><span>5、审批人部门</span><img src="{{url('signet/img/star.png')}}" alt="" /></div> <div class="partment"> <select id="applicantion_department_id2" name="applicantion_department_id2" style="width: 100%" > <option value="aa" >请选择部门</option> @if(!empty($department)) @foreach($department as $v ) <option value="{{$v['depart_id']}}" >{{$v['depart_name']}}</option> @endforeach @endif </select> </div> <div class="title"><span>审批人</span><img src="{{url('signet/img/star.png')}}" alt="" /></div> <div class="partment"> <select id="depart_audit_u_id" name="depart_audit_u_id" style="width: 100%" > <option value="aa" >请选择审批人</option> @if(!empty($user)) @foreach($user as $v ) <option value="{{$v['id']}}" >{{$v['name']}}</option> @endforeach @endif </select> </div>
<script> //审核人二级联动 $(function(){ $("#applicantion_department_id2").change(function(){ var data = $("#applicantion_department_id2").serialize(); data = data +"&_token={{csrf_token()}}"; $.ajax({ url:"/admin/user/aggregation2", //你的路由地址 type:"post", dataType:"json", data:data, timeout:30000, success:function(data){ $("#depart_audit_u_id").empty(); var count = data.length; var i = 0; var b="<option value='aa' >请选择审批人</option>"; for(i=0;i<count;i++){ b+="<option value='"+data[i].id+"'>"+data[i].name+"</option>"; } $("#depart_audit_u_id").append(b); } }); }); }) </script>
后台:
/** * 审核人部门、用户二级联动 * @author:chenbing * @date:2018-3-13 */ public function aggregation2(Request $request) { $ary_request = $request->input(); $users=WxUser::where("department",$ary_request['applicantion_department_id2'])->get()->toArray(); //该部门下的所有人 echo json_encode($users); }