目標(biāo)是構(gòu)建一個多層級的JSON[
{ name: "A_root", id:1, depth:0, child: [
{ name: "a1_1", depth:1, id:1
},
{ name: "a1_2", depth:1, id:2
}
]
},
{ name: "B_root" , id:2, depth:0
}
]用一個函數(shù)在任意地方添加節(jié)點(diǎn)比如可以在depth:0的這一級新增一個{name:'C_root',id:3,depth:0}也可以在depth:0 id:2這里增添一個子節(jié)點(diǎn)構(gòu)建成{ name:'B_root',id:2,depth:0,child:[{name:"b1_1",id:1,depth:1}] }以此類推新增子節(jié)點(diǎn),因?yàn)榭赡茉谌我馕恢眯略龉?jié)點(diǎn)所以希望能用一個函數(shù)解決
vue構(gòu)建不定復(fù)雜JSON
GCT1015
2018-07-21 08:37:22