var data1=[{
"tid": "1",
"text": "产品分析",
"children": [{
"tid": "1-1",
"text": "模拟产品计划",
"children": [{
"tid": "1-1-1",
"text": "用户行为分析1"
}, {
"tid": "1-1-2",
"text": "用户行为分析2"
}]
}]
var data2 = [
{"tid": "1", "text": "产品分析"},
{"tid": "1-1", "pid": "1", "text": "模拟产品计划"},
{"tid": "1-1-1", "pid": "1-1", "text": "用户行为分析1"},
{"tid": "1-1-2", "pid": "1-1", "text": "用户行为分析2"}
];
请问大神,这两种数据格式怎么互相转换?注意pid的增添!!!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
树形转为非树形很简单.
写一个递归判断如果children 不为空继续调用
每次返回一个对象数组, 把返回的数组contact, 最后输出总的数组集合
ps: 没有pid 建议给一个默认值
递归,传入child和pid就好了。。。