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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM