zTree想取非name的值展示

function updateType(nodes) {
    for (var i=0, l=nodes.length; i<l; i++) {
        var num = nodes[i].children ? nodes[i].children.length : 0;
        nodes[i].name = nodes[i].name + '(' +nodes[i].domain + ')';
        zTree.updateNode(nodes[i]);
        if (nodes[i].children && nodes[i].children.length > 0) {
            updateType(nodes[i].children);
        }
    }
}

vm.setCheck = function() {
    zTree = $.fn.zTree.getZTreeObj('categaryTreeDemo');
    var py = 'p',
    sy = 's',
    pn = 'p',
    sn = 's',
    type = { 'Y':py + sy, 'N':pn + sn};
    zTree.setting.check.chkboxType = type;
    vm.showCode('setting.check.chkboxType = { "Y" : "' + type.Y + '", "N" : "' + type.N + '" };');
};
        
vm.init = function(){
    var setting = {
        check: {
            enable: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick:onClick
        },
        view :{
            fontCss: vm.getFontCss
        }
    };

    vm.searchCondtion.filters['platform'] = vm.platform;

    var treeList=resourceService.build(CONST.host + CONST.api.getPermissionListTree);
    treeList.query(vm.searchCondtion).$promise.then(function(res) {
        var rootNode = [
            {
                id: 'rootNode',
                name: '根节点',
                children: []
            }
        ];
        var zNodes = res.data;
        rootNode[0].children = zNodes;
        var treeObj2 = $.fn.zTree.init($('#treeDemo'), setting, rootNode);
        vm.setCheck();
        $('#py').bind('change', true);
        $('#sy').bind('change', true);
        $('#pn').bind('change', true);
        $('#sn').bind('change', true);

        treeObj2.expandAll(false);//全部收缩

        function filter0(node) {//1级过滤
            return (node.level == 0);
        }
        function filter1(node) {//2级过滤
            return (node.level == 1);
        }
        function filter2(node) {//2级过滤
            return (node.level == 2);
        }

        var node0s = treeObj2.getNodesByFilter(filter0); //获取1级所有节点集合
        for (var int = 0; int < node0s.length; int++) {//遍历
            var node0 = node0s[int];
            treeObj2.expandNode(node0, true);//通过expandNode方法展开该级
            var node1s = treeObj2.getNodesByFilter(filter1); //获取2级所有节点集合
            for (var int1 = 0; int1 < node1s.length; int1++) {//遍历
                var node1 = node1s[int1];
                treeObj2.expandNode(node1, true);//通过expandNode方法展开该级
            }
        }
        var nodes = $.fn.zTree.getZTreeObj("treeDemo").getNodes();
        updateType(nodes);
    })
};

  

posted @ 2017-08-22 18:23  李晓菲  阅读(979)  评论(0编辑  收藏  举报