处理一段JS树形结构数据
100-500 佛山市
发布时间:昨天 14:35 人气:354
已报名威客 已报名威客 已报名威客 已报名威客 已报名威客 已报名威客
已有10人报名
需求详情
需求内容:

付款全款

源码需要

需求类型其他

报名截止:
加载中...
需求描述:
把一个正常的tree数据处理一下,
data是一个树形结构数据,需要给data做处理把相关节点移位,结合下面的例子找出规律并封装好一个处理的函数

目的:这样做是为了渲染tree的试试不用那么多层节点




例子1:
let data=[{
	"name": "发起",
	"children": [
		{
			"name": "莫二",
			"children":[]
		}
	],
}]

处理后的结果
result=[
	{
		"name": "发起",
		"children":[]
	},
	{
		"name": "莫二",
		"children":[]
	}
]

例子2:
let data=[{
	"name": "发起",
	"children": [
		{
			"name": "市场部",
			"children": [
				{
					"name": "总经理",
					"children": [],
				}
			],
		}, 
		{
			"name": "财务部",
			"children": [
				{
					"name": "总经理",
					"children": [],
				}
			],
		}
	],
}]

预期返回
data=[{
	"name": "发起",
	"children": [
		{
			"name": "市场部",
			"children": [
				{
					"name": "总经理",
					"children": [],
				}
			],
		}, 
		{
			"name": "财务部",
			"children": [
				{
					"name": "总经理",
					"children": [],
				}
			],
		}
	],
}]


例子3:
// 
let data=[{
	"name": "发起",
	"children": [
		{
			"name": "市场部",
			"children": [
				{
					"name": "总经理",
					"children": [
						{
							"name": "董事长",
							"children": [],
						}
					],
				}
			],
		}, {
			"name": "财务部",
			"children": [
				{
					"name": "总经理",
					"children": [
						{
							"name": "董事长",
							"children": [],
						}
					],
				}
			],
		}
	],
}]

预期返回
data=[{
	"name": "发起",
	"children": [
		{
			"name": "市场部",
			"children": [
				{
					"name": "总经理",
					"children": [],
				},
				
				{
					"name": "董事长",
					"children": [],
				}
			],
		}, 
		{
			"name": "财务部",
			"children": [
				{
					"name": "总经理",
					"children": [],
				},{
					"name": "董事长",
					"children": [],
				}
			],
		}
	],
}]

温馨提示:请勿私下转账和交易,产生风险和损失自行承担。平台担保全程免费,只收取提现方 0.6% 的支付接口费率【详情

友情提示:请勿相信任何以平台客服、网站管理为称呼的人进行交易,发现请及时举报曝光。阴阳需求,违规需求请勿承接,点左下角举报!

  • 推荐威客
    • 相似需求
      • 最新需求
      更多>>