數據準備前提:每一個子對象里有一個key是父對象的key
const? temObj? =? {? ?
? ? ? ? h1: {
? ? ? ? ? ? ? ? ? perent:? ‘ h0’,
? ? ? ? ? ? ? ? ? name: " 總監? "
? ? ? ? ? ? },
? ? ? ? h2:{
? ? ? ? ? ? ? ? ? perent: "h1",
? ? ? ? ? ? ? ? ? name:"xxx"
? ? ? ? ? ? },
? ? ? ? ? h3: {
? ? ? ? ? ? ? ? ? perent:"h2",
? ? ? ? ? ? ? ? ? name:"xx"
? ? ? ? ? ? }
}
for(const? key? in? temObj){? ?
? ? ? const? ? resultTree? =? {}
? ? ? const? ? present? =? temObj[ key ]
? ? ? If(!present) {? ?
? ? ? ? ? ? resultTree? =?
? ? ? }else {? ?
? ? ? ? ? ? ?
? ? ? ? }
}
2.外層不包含key的數組對象