This commit is contained in:
@@ -276,6 +276,43 @@ export function addFullName(
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 添加全名 如 祖先节点-父节点-子节点
|
||||
* @param treeData 已经是tree数据
|
||||
* @param labelName 标签的字段名称
|
||||
* @param splitStr 分隔符
|
||||
* @param callback 回调函数
|
||||
* @returns void 无返回值 会修改原始数据
|
||||
*/
|
||||
export function handleNode(
|
||||
treeData: any[],
|
||||
labelName = 'label',
|
||||
splitStr = '-',
|
||||
callback: Function,
|
||||
) {
|
||||
function addFullNameProperty(
|
||||
node: any,
|
||||
parentNames: any[] = [],
|
||||
parentNode: any = null,
|
||||
) {
|
||||
const fullNameParts = [...parentNames, node[labelName]];
|
||||
node.fullName = fullNameParts.join(splitStr);
|
||||
if (callback) {
|
||||
callback(node, parentNode);
|
||||
}
|
||||
if (node.children && node.children.length > 0) {
|
||||
node.children.forEach((childNode: any) => {
|
||||
addFullNameProperty(childNode, fullNameParts, node);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
treeData.forEach((item: any) => {
|
||||
addFullNameProperty(item);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* https://blog.csdn.net/Web_J/article/details/129281329
|
||||
* 给出节点nodeId 找到所有父节点ID
|
||||
|
Reference in New Issue
Block a user