标题:判断后不继续执行的FOR循环
取消只看楼主
lxf289
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-10-26
 问题点数:0 回复次数:1 
判断后不继续执行的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('-----')}
               
            }
        };
搜索更多相关主题的帖子: level 
2011-10-26 10:59
lxf289
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-10-26
得分:0 
找到问题了,写法不规范
  for (i = 0; i < jdata.length; i++)
忘了加 var
2011-10-26 11:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-353467-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.158112 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved