判断后不继续执行的FOR循环
一个 自引用 函数,条件判断为FALSE后 后面的循环就不执行了,为什么呢....代码如下程序代码:
var znodes = [ {"id": 1,"pId": null,"name": "父节点1","childs": [ {"id": 11,"pId": 1,"name": "a-a","childs": [ {"id": 12,"pId": 11,"name": "a-a-a","level": 2,"childs": [ {"id": 101,"pId": 12,"name": "a-a-a-a"}, {"id": 102,"pId": 12,"name": "a-a-a-b"}]}]}]}, {"id": 2,"pId": null,"name": "父节点2","childs": [ {"id": 21,"pId": 2,"name": "b-a"}]}, {"id": 3,"pId": null,"name": "父节点3","childs": []} ]; function jsonview(jdata) { for (i = 0; i < jdata.length; i++) { console.log(jdata[i]['name']) if (jdata[i].hasOwnProperty('childs') && jdata[i]['childs'].length > 0) { jsonview(jdata[i]['childs'])} else {console.log('-----')} } };