1:代码
/**
*
* @param treeList 排序好的树结构
* @param metaList 总数据
* @param temp 临时对象
*/
private void getTreeModelList(List<TreeModel> treeList,List<SysPermission> metaList,TreeModel temp) {
for (SysPermission permission : metaList) {
//获取父id
String tempPid = permission.getParentId();
//创建树结构对象
TreeModel tree = new TreeModel(permission.getId(), tempPid, permission.getName(),permission.getRuleFlag(), permission.isLeaf());
// 临时对象为空,父id为空,拿到一级菜单
if(temp==null && oConvertUtils.isEmpty(tempPid)) {
treeList.add(tree);
//判断是否有子集,如果有则进行循环添加子集集合
if(!tree.getIsLeaf()) {
//这里有用就的是临时对象,给临时对象添加子集集合
getTreeModelList(treeList, metaList, tree);
}
}else if(temp!=null && tempPid!=null && tempPid.equals(temp.getKey())){
//这里首先获取临时对象,然后给临时对象添加子集集合
temp.getChildren().add(tree);
//判断当前对象是否有子集,如若有则进行循环添加子集集合
if(!tree.getIsLeaf()) {
//这里就是使用临时对象,给临时对象添加子集集合
getTreeModelList(treeList, metaList, tree);
}
}
}
}
2:数据结构
[
{
"key": "9502685863ab87f0ad1134142788a385",
"title": null,
"slotTitle": "首页",
"isLeaf": true,
"icon": null,
"ruleFlag": 0,
"scopedSlots": {
"title": "hasDatarule"
},
"children": null,
"parentId": "",
"label": null,
"value": "9502685863ab87f0ad1134142788a385"
},
{
"key": "d7d6e2e4e2934f2c9385a623fd98c6f3",
"title": null,
"slotTitle": "系统管理",
"isLeaf": false,
"icon": null,
"ruleFlag": 0,
"scopedSlots": {
"title": "hasDatarule"
},
"children": [
{
"key": "3f915b2769fc80648e92d04e84ca059d",
"title": null,
"slotTitle": "用户管理",
"isLeaf": false,
"icon": null,
"ruleFlag": 0,
"scopedSlots": {
"title": "hasDatarule"
},
"children": [
{
"key": "1260929666434318338",
"title": null,
"slotTitle": "用户编辑",
"isLeaf": true,
"icon": null,
"ruleFlag": 0,
"scopedSlots": {
"title": "hasDatarule"
},
"children": null,
"parentId": "3f915b2769fc80648e92d04e84ca059d",
"label": null,
"value": "1260929666434318338"
}
],
"parentId": "d7d6e2e4e2934f2c9385a623fd98c6f3",
"label": null,
"value": "3f915b2769fc80648e92d04e84ca059d"
}
],
"parentId": "",
"label": null,
"value": "d7d6e2e4e2934f2c9385a623fd98c6f3"
}
]