layui.treeTable树形表格下拉形式
var rel = treeTable.render({
elem: '#comList';
id: 'f_comList',
url: layui,common.sysBaseURL;
headers:{
'Content-type':'application/x-www-form-urlencoded;charset=utf-8',
"Access-Token": sessionStotage.getItem("token")
},
methon:'get',
cols:[[
{field:'id',title:'ID',hide:true}
]],
style:'margin-top:0',
tree:{
idName: 'id',
pidName: 'parent',
iconIndex:1,
isPidDate:true
}
})
//后台返回参数必须含有ID和parent,父id和子ID关联才能形成treeTable树形下拉
layui.treeSelect树形下拉
前端
treeSelect.render({
elem: '#tree',
data:layui.common.sysBaseURL,
type: 'get',
placeholder: '请选择机构',
search: true,
style: {
folder: {
enable:true
},
line: {
enable:true
},
}
})
后台
public List<ComTreeResDto> getUserComList(ComEditDto comEditDto){
List<BscComT> comList = comDao.getUserComTree(comEditDto);
List<ComTreeResDto> comTreeList = transTreeComList(comList,(long) 0); //0为父id
return comTreeList;
}
private List<ComTreeResDto> transTreeComList(List<BscComT> comList ,Long parentId){
List<ComTreeResDto> comTreeList = null;
for(BscComT bscComT : comList ){
if(parentId.equals(bscComT.getParentId())){
if(comTreeList = null){
comTreeList = new ArrayList();
}
ComTreeResDto comTreeResDto = new ComTreeResDto();
comTreeResDto.setId(bscComT.getComCode());
comTreeResDto.setName(bscComT.getComCode() + "_" + bscComT.getComSname);
comTreeResDto.setChildren(transTreeComList(comList,bscComT.getId()));
comTreeList.add(comTreeResDto);
}
}
return comTreeList;
}
//当然treeSelect的缺点也很明显,只能实现树形下拉,不能多选,辣鸡
layui.tree
前端
$.ajax({
url: layui.common.sysBaseURL,
headers:{
'Content-type':'application/x-www-form-urlencoded;charset=utf-8',
"Access-Token": sessionStotage.getItem("token")
},
methon:'get',
dataType: "json",
async: false,
data:{comCode:user.userCom},
success:function(data){
da = tranform(data.data);
}
})
var rel = tree.render({
elem: '#tree',
showCheckbox :true,
checkChild :false,
data: da,
id: 'id',
})
function tranform(){
var arr = [];
var json = {};
for(var i in obj){
json = {};
addkey(json,obj,i);
if(obj[i].children !=null){
json['children'] = tranform(obj[i].children);
}else{
json['children'] = obj[i].children;
}
arr[i] = json;
}
return arr;
}
function addkey(json,obj,i){
json['title'] = obj[i].name;
json['id'] = obj[i].id;
}
后台
public List<ComTreeResDto> getUserComList(ComEditDto comEditDto){
List<BscComT> comTreeList = new ArrayList<>();
List<ComTreeResDto> childrenList = new ArrayList<>();
List<ComTreeResDto> treeList= new ArrayList<>();
ComTreeResDto tree;
comTreeList = comDao.findAllComByComCode(comEditDto);
if(comTreeList!=null){
for(BscComT comrow : comTreeList ){
tree = new ComTreeResDto();
tree.setId(comrow .getComCode());
tree.setName(comrow.getComCode() + "_" + comrow.getComSname());
childrenList = this.getChildrenTree(comrow.getId());
tree.setChlidren(childrenList );
treeList.add(tree);
}
}
return treeList;
}
public List<ComTreeResDto> getChildrenTree(Long parent){
ComEditDto comEditDto = new ComEditDto();
ComEditDto.setParent(parent);
ComTreeResDto tree;
List<BscComT> treeList= new ArrayList<>();
List<ComTreeResDto> childrenList;
List<ComTreeResDto> treeLst= new ArrayList<>();
treeList = comDao.getChlidrenTreeLst(comEditDto);
for(BscComT list : treeList){
tree = new ComTreeResDto();
tree.setId(list.getComCode());
tree.setName(list.getComCode() + "_" + list.getComSname());
childrenList = this.getChildrenTree(list.getId());
tree.setChlidren(childrenList );
treeList.add(tree);
}
return treeLst;
}