根据idsTwo/中的数据,从numeData找出id相同的数据,保留对应的层级,id没有出现的数据全部删除掉,层级不删除,依旧保留
idsOne也可以依据上面的方法找出对应的层级,将找出的数据保存在data中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var numeData = [{
id: '1',
name: "我",
children: [{
id: '11',
name: "两个我",
children: [{
id: '111',
name: "三个我",
}, ]
}, {
id: '01',
name: "01我",
children: [{
id: '001',
name: "001我",
}, ]
}]
}, {
id: '2',
name: "你",
children: [{
id: '22',
name: "两个你",
children: [{
id: '222',
name: "三个你",
}, ]
}, {
id: '02',
name: "02你",
children: [{
id: '002',
name: "002你",
children: [{
id: '0002',
name: '0002你'
}]
}, ]
}]
}, {
id: '3',
name: "他",
children: [{
id: '33',
name: "两个他",
children: [{
id: '333',
name: "三个他",
}, ]
}, {
id: '03',
name: "03他",
children: [{
id: '003',
name: "003他",
children: [{
id: '0003',
name: '0003他'
}]
}, ]
}]
}]
var data =[]
var idsTwo = ['1','111','002','0003','02','001','222']
var idsOne = ['0002','01','002','003','02','001','222']
// 根据idsTwo/中的数据,从numeData找出id相同的数据,保留对应的层级,id没有出现的数据全部删除掉,层级不删除,依旧保留
// idsOne也可以依据上面的方法找出对应的层级,将找出的数据保存在data中
</script>
</body>
</html>