日期:2014-05-16 浏览次数:20444 次
var i1={
id:1,
name:1,
Is:[{
id:2,
name:2
},{
id:3,
name:3,
Is:[{
id:4,
name:4,
Is:[{
id:6,
name:6
},{
id:7,
name:7
}]
},{
id:5,
name:5,
Is:[{
id:8,
name:8
},{
id:9,
name:9
}]
}]
}]
}
var i1={
id:1,
name:1,
Is:[{
id:2,
name:2
},{
id:3,
name:3,
Is:[{
id:4,
name:4,
Is:[{
id:6,
name:6
},{
id:7,
name:7
}]
},{
id:5,
name:5,
Is:[{
id:8,
name:8
},{
id:9,
name:9
}]
}]
}]
};
function fn(data , deep){
var split = '';
for(var i = 0 ; i < deep ; ++i){
split+=' ';
}
split+='
------解决方案--------------------
-';
console.log(split+data.name);
if(typeof data.Is!='undefined'){
for(var i in data.Is){
fn(data.Is[i] , deep+1);
}
}
}
fn(i1,0);