JavaScript 树形结构数据递归遍历函数
function treelist(arr, id = 0) { \n let arry = []; \n arr.forEach(item => { \n if (item.parent_id === id) { \n let obj = { \n id: item.id, \n title: item.title, \n children: treelist(arr, item.id) \n }; \n arry.push(obj); \n } \n }); \n return arry; \n} \n\nconsole.log(treelist(arrayData));
原文地址: https://www.cveoy.top/t/topic/qqpl 著作权归作者所有。请勿转载和采集!