<sqlid="sysOrgColumn">
o.org_no,
o.org_name,
o.parent_no
</sql><selectid="getAllOrg"resultType="com.base.modules.sys.entity.SysOrg">
SELECT
<includerefid="sysOrgColumn"/>
,so.org_name parent_name
FROM sys_org o
LEFT JOIN sys_org so ON o.parent_no = so.org_no
</select>
前端
封装树形数据方法
/**
* 树形数据转换
*/exportfunctiontreeDataTranslate(data, id ='id', pid ='parentId'){let res =[]let temp ={}for(let i =0; i < data.length; i++){
temp[data[i][id]]= data[i]}for(let k =0; k < data.length; k++){if(temp[data[k][pid]]&& data[k][id]!== data[k][pid]){if(!temp[data[k][pid]]['children']){
temp[data[k][pid]]['children']=[]}if(!temp[data[k][pid]]['_level']){
temp[data[k][pid]]['_level']=1}
data[k]['_level']= temp[data[k][pid]]._level +1
temp[data[k][pid]]['children'].push(data[k])}else{
res.push(data[k])}}return res
}