数据格式
data:[
{
id: "a0a5c642e45c452b821d2f13c1ff2515",
label: "人力资源部",
pid: "",
disabled: true,
children: [
{
children:[]
disabled:true
id:"e30b8078383d4ddd8ccc2ab4fd8c2b52"
label:"张大三"
pid:"a0a5c642e45c452b821d2f13c1ff2515"
}
]
}
递归算法
var recursiveFunction = function(){
var ul='';
var appednMenu = function (data) {
data.forEach(function (item) {
if(item.deptChildList){
ul+='<li>'+item.name+'<ul>';
appednMenu(item.deptChildList);
ul+='</ul>';
for(var i in item.userChildList){
ul += '<input type="checkbox" name="person" value="'+item.userChildList[i].id+'" title="'+item.userChildList[i].name+'" lay-skin="primary">';
}
ul+= '</li>';
}else {
ul+='<li>'+item.name+'</li>';
}
})
};
appednMenu(res.data.departmentArray);
$('.tree').html(ul);
};
recursiveFunction()