小弟初学js,遇到一个难题,关于把一个多层数据结构的转换成treeview可识别的格式问题原数据格式为:{"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节点的值(即"body")每个节点的child如果不在structure一级节点中,则认为是叶子节点想了一天,没有好办法,来求助各位前辈
阿波罗的战车
相关分类