import type { FieldNames } from './props';
|
|
export const TREE_PATH_LABEL_FIELD = '__jnpfTreePathLabel';
|
|
export function setTreePathLabels(treeData: any[], fieldNames: Required<FieldNames>, parentLabels: string[] = []) {
|
for (const node of treeData) {
|
const label = node[fieldNames.label];
|
const labels = label === undefined || label === null || label === '' ? parentLabels : [...parentLabels, String(label)];
|
node[TREE_PATH_LABEL_FIELD] = labels.join('/');
|
|
const children = node[fieldNames.children];
|
if (Array.isArray(children) && children.length) setTreePathLabels(children, fieldNames, labels);
|
}
|
return treeData;
|
}
|