jtopo树结构方法积累

1、计算最外层最大节点个数:

function getMaxLeafCnt(data) {
        var maxcnt = 0;//本身
        var children = data.children == undefined ? new Array() : data.children;
        if (children.length > 0) {
            for (var i = 0; i < children.length; i++) {
                var f = children[i];
                if (f.children == undefined) {
                    maxcnt++;
                } else {
                    maxcnt += getMaxLeafCnt(f);
                }
            }
        }
        return maxcnt;
    }

2、树形布局,无须自己计算位置:

    // 树形布局
    scene.doLayout(JTopo.layout.TreeLayout('down', 30, 107));

3、设置警告:

setInterval(function () {
        for (var i = 0; i < nodeAlarms.length; i++) {
            var s = nodeAlarms[i];
            if (s.alarm == '二级告警') {
                s.alarm = null;
            } else {
                s.alarm = '二级告警'
            }
        }
    }, 600);

 

转载于:https://www.cnblogs.com/time-on/p/8336764.html

你可能感兴趣的:(jtopo树结构方法积累)