JS递归遍历树结构
Posted S1ow
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS递归遍历树结构相关的知识,希望对你有一定的参考价值。
<script>
var arrs = [];
function haha()
var data = [
name: '中国',
children: [
name: '教第三节课',
,
name: '教呼呼',
children: [
name: '大一',
children: [
name: '课程1',
children: [
name: '1231'
,
name: '121'
]
,
name: '课程2',
children: [
name: '1232'
,
name: '122'
]
,
name: '课程3',
children: [
name: '1233'
,
name: '123'
]
,
]
]
,
name: '活动',
children:null
]
];
getArray(data,'活动');
console.log(data);
for(var i in undefined)
alert(123);
function getArray(data,name)
for (var i in data)
console.log('i',i);
console.log('datai',data[i].children);
if (data[i].name == name)
console.log(data[i]);
break;
else
getArray(data[i].children, name);
</script>
以上是关于JS递归遍历树结构的主要内容,如果未能解决你的问题,请参考以下文章