1.原始数据:数据结构为一个二维表list存的树:[json1,json2...]json的格式为:{id,name,...deptPreId(树节点)}原始数据例子:[{"id":1,"deptName":"B","deptFullname":"A_B","deptLevel":2,"deptPreId":2,},{"id":2,"deptName":"A","deptFullname":null,"deptLevel":1,"deptPreId":null,},{"id":3,"deptName":"C","deptFullname":null,"deptLevel":3,"deptPreId":1,},{"id":4,"deptName":"wwxxX","deptFullname":null,"deptLevel":null,"deptPreId":1},{"id":5,"deptName":"123124124","deptFullname":null,"deptLevel"2,"deptPreId":1}];2.目标数据:将其转换为下面目标数据,也是一个类似的树,有树形层次:其中如果指定child的list的话如何找到其父和组,并生成相应的树。数据格式如下:list:[json1,json2]json:{json,childList}Childlist:[json1,json2]目标数据例子:data=[{"id":2,"deptName":"A","deptFullname":null,"deptLevel":1,"deptPreId":null,Child:[{"id":1,"deptName":"B","deptFullname":"A_B","deptLevel":2,"deptPreId":2,Child:[{"id":3,"deptName":"C","deptFullname":null,"deptLevel":3,"deptPreId":1,}]},{"id":5,"deptName":"123124124","deptFullname":null,"deptLevel"2,"deptPreId":1}]}]通过子类去寻找父类会涉及到父类合并的问题,比如树形结构:A1->B1->C1,A1->B1->C2,A1->B1->C2->D2,比如我现在要通过list,[D2,C1]去寻找D2,所有的祖辈,当回溯到B1的时候要进行合并,但是C2和D2第几次循环查到C2,D2是不确定的。所以和参考代码给出的解决方法有所区分类似问题:通过父类去寻找子类:https://segmentfault.com/q/10...
FFIVE
白板的微信
相关分类