$.ajax({
url: '${ctx}appUser/queryPartJob.html?userId='+"${appUser.id}",
type: 'post',
dataType: 'json',
success: function(data){
var arr=data.data;
var continentOption='';
var i=1;
$.each(arr, function(idx, obj) {
i++;
continentOption += '<div class="form_input_box width20"><h1>负责部门'+i+'</h1><div><input type="text" id="deptName" name="deptName" readonly="readonly" value="'+obj.deptName+'" ></div></div> <div class="form_input_box width20"><h1>部门负责人</h1><div><input type="text" id="deptHead" name="deptHead" readonly="readonly" value="'+obj.deptHead+'"></div></div><div class="form_input_box width20"><h1>现任岗位</h1><div><input type="text" id="employeeJobs" name="employeeJobs" readonly="readonly" value="'+obj.partJob+'" ></div></div><div class="form_input_box width20"><h1>管理权重</h1><div><input type="text" id="manageWeights" name="manageWeights" readonly="readonly" value="'+obj.manageWeights+'"></div></div><div class="form_input_box width20"><h1>累计权重</h1> <div><input type="text" id="heapWeights" name="heapWeights" readonly="readonly" value="'+obj.heapWeights+'" ></div></div>'
});
$("#partDept").append(continentOption); //partDept这个是div的id直接插入进去
layui.form.render();
},
error: function(data){
layer.msg('加载下拉列表失败!',{
icon: 0,time: 1000
});
}
});
根据ajax成功后返回值,返回值为数组,将数组遍历,并且拼接成表格样式,然后在根据所要插入的div的id将表格插入带该div内