请问这个数据怎么处理：点击树形结构节点，右侧面包屑按照父子节点显示名字，感谢解答！

• 67

//以下是数据结构

``````  {
"goodsCategoryId": 14838,
"goodsCategoryName": "男装",
"goodsCategoryLevel": 1,
"goodsCategoryFatherId": 0,
"childCount": null,
"goodsCategoryChildList": [
{
"goodsCategoryId": 14839,
"goodsCategoryName": "男上装",
"goodsCategoryLevel": 2,
"goodsCategoryFatherId": 14838,
"childCount": null,
"goodsCategoryChildList": [
{
"goodsCategoryId": 14841,
"goodsCategoryName": "男式T恤",
"goodsCategoryLevel": 3,
"goodsCategoryFatherId": 14839,
"childCount": null,
"goodsCategoryChildList": []
},
{
"goodsCategoryId": 14840,
"goodsCategoryName": "男式背心/马夹",
"goodsCategoryLevel": 3,
"goodsCategoryFatherId": 14839,
"childCount": null,
"goodsCategoryChildList": []
}
]
}
]
},``````

2 个回答
✓ 已被采纳
``````/**
* 找树型节点的路径
* @param list 树型数据
* @param filter 过滤条件
* @returns [] 结果数组
*/
let findTreePath = (list = [], filter = {}) => {
return [...list].reduce((acc, cur, idx, arr) => {// 解构取消引用
var res = findTreePath(cur.children, filter); // 查找下级节点
if ( Object.entries(filter).every(([key, val]) => cur[key] === val) ||res.length) {
//找到子节点
acc.push(cur.label, ...res); //添加当前节点和子节点
arr.length = 0; //结束reduce循环
}
return acc;
}, []);
};``````