小弟初學js,遇到一個難題,關于把一個多層數(shù)據(jù)結構的轉換成treeview可識別的格式問題原數(shù)據(jù)格式為:{"root":"body","structure":{"body":["head","foot"],"head":["control","tabs"],"control":["c123","c456","c789"],"tabs":["33","44"],"foot":["footLeft","divEnd"],"footLeft":["footLeftContainer"],"footLeftContainer":["add22","ffff","fff"],"divEnd":["divEnd$111"]}};期望處理成的格式為:[{text:"body",nodes:[{text:"head",nodes:[{text:"control",nodes:[{text:"c123"},{text:"c456"},{text:"c789"}]},{text:"tabs",nodes:[{text:"t33"},{text:"t44"}]}]},{text:"foot",nodes:[{text:"footLeft",nodes:[{text:"footLeftContainer",nodes:[{text:"add22"},{text:"ffff"},{text:"fff"}]}]},{text:"divEnd",nodes:[{text:"divEnd$111"}]}]}]}]原理就是從structure中層層找child,起始點是root節(jié)點的值(即"body")每個節(jié)點的child如果不在structure一級節(jié)點中,則認為是葉子節(jié)點想了一天,沒有好辦法,來求助各位前輩
新手上路,【比較難】JS多層遞歸遍歷大佬們有什么好的建議?
千萬里不及你
2019-10-16 10:15:22