码迷,mamicode.com
首页 > 编程语言 > 详细

简单 递归取到数组子数组的值

时间:2017-12-21 20:06:10      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:log   测试   actor   cto   page   fun   blog   dep   UI   

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible"
content="IE=edge">
<title>Page Title</title>
<meta name="viewport"
content="wIdth=device-wIdth, initial-scale=1">
<link rel="stylesheet"
type="text/css"
media="screen" />
<script>
var items = [
{
Id: 1,
name: ‘产品部‘,
Children: []
},
{
Id: 2,
name: ‘项目部‘,
Children: [
{
Id: 4,
name: ‘项目部1‘,
Children: [
{
Id: 6,
name: ‘项目部111‘,
Children: []
},
]
},
{
Id: 5,
name: ‘项目部2‘,
Children: []
},
]
},
{
Id: 3,
name: ‘测试部‘,
Children: []
},
]
var a = [2,5]

function factorial(departmentList, departmentIds) {
for (let j = 0; j < departmentIds.length; j++) {
for (let i = 0; i < departmentList.length; i++) {
if (departmentIds[j] == departmentList[i].Id) {
if (j == departmentIds.length - 1) {
return JSON.stringify(departmentList[i]);
}
return this.factorial(departmentList[i].Children, departmentIds);
}
}
}
}
console.log(this.factorial(items, a));



</script>
</head>

<body>

</body>

</html>

简单 递归取到数组子数组的值

标签:log   测试   actor   cto   page   fun   blog   dep   UI   

原文地址:http://www.cnblogs.com/xinhang/p/8082201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!