复制
收藏
提问
全网

categorys数组内部存储的一个json对象代表一个课程分类信息,每个课程分类都有一个 parent属性记录父分类的id 比如{"id":"02","parent":"01","name":"html/css"}中parent":"01" 找id=01的父分类信息{"id":"01","parent":"00","name":"前端技术"} 完整例子 var categorys=[{"id":"01","parent":"00","name":"前端技术"},{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"},{"id":"04","parent":"00","name":"后端技术"},{"id":"05","parent":"04","name":"java"}]; 转换成父子的树形结构,在顶级分类内部加入children属性存储子分类的集合 parent=="00" 代表当前分类是顶级分类 结果: var categorys=[{"id":"01","parent":"00","name":"前端技术","children":[{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"}]} , {"id":"04","parent":"00","name":"后端技术","children":[{"id":"05","parent":"04","name":"java"}]} ];

83aebc147
2个月前
全网
文档
学术
百科
知识库
时间不限
自动

理解问题categorys数组内部存储的一个json对象代表一个课程分类信息,每个课程分类都有一个 parent属性记录父分类的id 比如{"id":"02","parent":"01","name":"html/css"}中parent":"01" 找id=01的父分类信息{"id":"01","parent":"00","name":"前端技术"} 完整例子 var categorys=[{"id":"01","parent":"00","name":"前端技术"},{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"},{"id":"04","parent":"00","name":"后端技术"},{"id":"05","parent":"04","name":"java"}]; 转换成父子的树形结构,在顶级分类内部加入children属性存储子分类的集合 parent=="00" 代表当前分类是顶级分类 结果: var categorys=[{"id":"01","parent":"00","name":"前端技术","children":[{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"}]} , {"id":"04","parent":"00","name":"后端技术","children":[{"id":"05","parent":"04","name":"java"}]} ];

已完成理解categorys数组内部存储的一个json对象代表一个课程分类信息,每个课程分类都有一个 parent属性记录父分类的id 比如{"id":"02","parent":"01","name":"html/css"}中parent":"01" 找id=01的父分类信息{"id":"01","parent":"00","name":"前端技术"} 完整例子 var categorys=[{"id":"01","parent":"00","name":"前端技术"},{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"},{"id":"04","parent":"00","name":"后端技术"},{"id":"05","parent":"04","name":"java"}]; 转换成父子的树形结构,在顶级分类内部加入children属性存储子分类的集合 parent=="00" 代表当前分类是顶级分类 结果: var categorys=[{"id":"01","parent":"00","name":"前端技术","children":[{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"}]} , {"id":"04","parent":"00","name":"后端技术","children":[{"id":"05","parent":"04","name":"java"}]} ];

展开阅读网页

更专业一些
转笔记
专业
categorys数组内部存储的一个json对象代表一个课程分类信息,每个课程分类都有一个 parent属性记录父分类的id 比如{"id":"02","parent":"01","name":"html/css"}中parent":"01" 找id=01的父分类信息{"id":"01","parent":"00","name":"前端技术"} 完整例子 var categorys=[{"id":"01","parent":"00","name":"前端技术"},{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"},{"id":"04","parent":"00","name":"后端技术"},{"id":"05","parent":"04","name":"java"}]; 转换成父子的树形结构,在顶级分类内部加入children属性存储子分类的集合 parent=="00" 代表当前分类是顶级分类 结果: var categorys=[{"id":"01","parent":"00","name":"前端技术","children":[{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"}]} , {"id":"04","parent":"00","name":"后端技术","children":[{"id":"05","parent":"04","name":"java"}]} ];
不在提醒

更专业内容正在努力生成中
知识树
categorys数组内部存储的一个json对象代表一个课程分类信息,每个课程分类都有一个 parent属性记录父分类的id 比如{"id":"02","parent":"01","name":"html/css"}中parent":"01" 找id=01的父分类信息{"id":"01","parent":"00","name":"前端技术"} 完整例子 var categorys=[{"id":"01","parent":"00","name":"前端技术"},{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"},{"id":"04","parent":"00","name":"后端技术"},{"id":"05","parent":"04","name":"java"}]; 转换成父子的树形结构,在顶级分类内部加入children属性存储子分类的集合 parent=="00" 代表当前分类是顶级分类 结果: var categorys=[{"id":"01","parent":"00","name":"前端技术","children":[{"id":"02","parent":"01","name":"html/css"},{"id":"03","parent":"01","name":"javascript"}]} , {"id":"04","parent":"00","name":"后端技术","children":[{"id":"05","parent":"04","name":"java"}]} ];
- 数据结构转换原理? - 如何优化树形结构转换算法? - 树形数据在前端应用场景? - JSON数据树形结构解析技巧? - 数据库中树形结构存储方法?
如何处理无父元素节点?
顶级分类如何识别?

以上内容由AI搜集生成,仅供参考

在线客服