<select name="deptmgr" lay-filter="FirstSelect" id="FirstSelect" lay-search=""> <#--此处动态生成select--> </select> -------------------------------------------------------------- //监听头部工具事件 table.on("toolbar(deptTable)", function (obj) { switch (obj.event) { case ‘add‘: var FirstSelect= $("#FirstSelect"); commonFun.loadDeptSelect(FirstSelect);//加载后台数据,渲染select openAddFirstDept();//打开添加一级部门弹出层 break; case ‘batchDelete‘: layer.msg(‘批量删除‘); break; } ; }); ------------------------------------------------------------ //加载后台数据,渲染到select中 var commonFun = { //canshu:要渲染的select的jquery对象 loadDeptSelect: function (canshu) { var option = "<option value=‘-1‘>请选择</option>";//初始化option的选项 $.post("getComEmp", function (res) { var str = ""; for (i = 0; i < res.length; i++) { option += "<option value=‘" + res[i].empname + "‘;"; option += ">" + res[i].empname + "</option>"; canshu.html(option); } form.render(‘select‘);//重新渲染select }, "json"); } }; ------------------------------------------------------- //打开一级部门添加页面 function openAddFirstDept() { mainIndex = layer.open({ type: 1 , title: ‘添加一级部门‘ , content: $(‘#addFirstDeptDiv‘) , area: [‘800px‘] , success: function (index) { //清空表单数据 $("#dataFrm")为jquery对象,没有reset方法,需要转js对象 $("#dataFrm")[0],再调用js的reset()方法来清空表单 $("#dataFrm")[0].reset(); $.ajax({ url: "getComEmp" , success: function (result) { console.log(result); } }); } }) }
原文:https://www.cnblogs.com/svipero/p/12830644.html