写一个函数,传入任意值,模糊查询numeData中name的属性值,如果有匹配到,找出对应的层级,返回一个新数组,不包含的数据全部删除掉,层级不删除,依旧保留
比如,传入y,就返回name中的值有包含y的所有层级和他的父层级,传入03,就返回name中有03的所有层级,和父层级
<!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: "我w",
children: [{
id: '11',
name: "两个我12",
children: [{
id: '111',
name: "三个我",
}, ]
}, {
id: '01',
name: "01我3",
children: [{
id: '001',
name: "001我",
}, ]
}]
}, {
id: '2',
name: "你",
children: [{
id: '22',
name: "两个你56",
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: "两个他_3y",
children: [{
id: '333',
name: "三个他",
}, ]
}, {
id: '03',
name: "03他",
children: [{
id: '003',
name: "003他",
children: [{
id: '0003',
name: '0003他'
}]
}, ]
}]
}]
// 写一个函数,传入任意值,模糊查询numeData中name的属性值,如果有匹配到,找出对应的层级,返回一个新数组,不包含的数据全部删除掉,层级不删除,依旧保留
// 比如,传入y,就返回name中的值有包含y的所有层级和他的父层级,传入03,就返回name中有03的所有层级,和父层级
</script>
</body>
</html>