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"}]} ];」
展开阅读网页