layui动态生成下拉列表

<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.confirm('真的删除么?<br/>(含有子部门的将无法删除...)', function (index) {
layer.close(index);
//向服务端发送删除指令
batchDeleteDept();//执行批量删除函数
});
break;
}
;
});
------------------------------------------------------------ 
//加载后台数据,渲染到select中
var commonFun = {
//canshu:要渲染的select的jquery对象
loadDeptSelect: function (canshu, mgr) {

var option = "<option value = ''>请选择</option>";
$.post("getComEmp", {'oldDeptmgr': mgr}, function (res) {

console.log(res);
console.log(mgr);

for (i = 0; i < res.length; i++) {

option += "<option value = '" + res[i].empno + "' ";
if (res[i].empno == mgr) {
option += "selected";
}
option += ">" + res[i].empname + "</option>";
canshu.html(option);
}
form.render('select');//重新渲染select
}, "json");
}
};
------------------------------------------------------
//控制层
//获取普通员工和当前部门经理的的信息--普通员工,职位编号为016
@RequestMapping("/getComEmp")
@ResponseBody
public List<Emp> getComEmp(String oldDeptmgr) {

EmpExample example = new EmpExample();
EmpExample.Criteria criteria = example.createCriteria();
criteria.andPosinoEqualTo("016");
List<Emp> emps = null;
Emp nowMgr = null;
try {
//查询当前部门是否存在部门经理
nowMgr = empService.selectByPrimaryKey(oldDeptmgr);
//System.out.println("查询当前部门是否存在部门经理:" + nowMgr);
emps = empService.selectByExample(example);
if (nowMgr != null) {
emps.add(nowMgr);
}
} catch (Exception e) {
e.printStackTrace();
}
return emps;
}

 

posted @ 2020-05-05 14:26  记忆留一道伤疤  阅读(970)  评论(0编辑  收藏  举报