猿问

有大佬遇到过这个问题吗:平级转树结构谢谢哈~

vardata={
"organization":[
{
"id":"1",
"pid":"0",
"organization":"/A"
},
{
"id":"2",
"pid":"0",
"organization":"/AA"
},
{
"id":"11",
"pid":"1",
"organization":"/A/B"
},
{
"id":"22",
"pid":"2",
"organization":"/AA/BB"
},
{
"id":"44",
"pid":"2",
"organization":"/AA/CC"
}
],
"user":[
{
"id":"xxxx",
"pid":"2",
"email":"yu@test.com",
"organization":"/A",
"display_name":"玉"
},
{
"id":"yyy",
"pid":"2",
"email":"yy@test.com",
"organization":"/A/B",
"display_name":"哈"
},
{
"id":"zzzz",
"pid":"22",
"email":"nn@test.com",
"organization":"/AA/BB",
"display_name":"欧式"
},
{
"id":"hhhh",
"pid":"44",
"email":"yfef@test.com",
"organization":"/AA/CC",
"display_name":"红"
},
{
"id":"effef",
"pid":"44",
"email":"yfesf@test.com",
"organization":"/AA/CC",
"display_name":"xe"
}
]
}
如果是organization数组中的话title字段显示组织,如果是user数组中的话title字段显示email
如何把以上结构转成树结构?
PIPIONE
浏览 351回答 2
2回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答