PHP技术,网站开发,PHP,PHP学习,Python学习,PHP开发,人工智能,大数据服务

PHP+Python » 前端设计 » jstree选中节点与展开节点

jstree选中节点与展开节点

此文被围观368日期: 2019-06-03 分类 : 前端设计  标签:  ·····

项目使用的jstree树结构插件,因为是异步并且不是全部展开的。

但是在编辑的时候需要选中子节点并展开子节点所在的父节点

var currDeptId = ["0940903B-D72F-B4EB-BB32-EF0459603CAF","51AFE427-72C9-7196-708C-A96F1860211C",
"6304C6DA-D7FE-4E74-32AF-554AFEC0F91A","C0EA460A-F19C-80B3-16E9-84393B6EBCEB",
"20BD3FB5-4C34-BFD6-32FB-62AC5CC9B4DF","70E79C63-F981-1501-BFF6-C6AF5F8E74D8",
"96B48AF1-481A-E506-D493-81ECE2E90CF1","F4B3D43B-5F82-A683-DD41-E0D06698B845",
"9B6AFFA9-F815-3616-B0F9-452778063EB1"];//包含选中的节点与选中节点的父节点
var selectedId = ["0940903B-D72F-B4EB-BB32-EF0459603CAF","20BD3FB5-4C34-BFD6-32FB-62AC5CC9B4DF",
"70E79C63-F981-1501-BFF6-C6AF5F8E74D8","F4B3D43B-5F82-A683-DD41-E0D06698B845",
"96B48AF1-481A-E506-D493-81ECE2E90CF1","9B6AFFA9-F815-3616-B0F9-452778063EB1"];//选中节点
//jstree加载回调函数
function TreeCallback(target, data, textStatus) {
    if (typeof currDeptId != 'undefined' && currDeptId != "") {
        var l = currDeptId.length;
        var t = setInterval(function () {
            if (l<=0) {
                clearInterval(t);
                return
            }
            for (var i in currDeptId) {
                var select_node = currDeptId[i];
                var selectNode = $('#' + select_node);
                if (selectNode.length > 0) {
                    //展开节点
                    $('#jsTree_multi-select-tree_orgnization').jstree('open_node', select_node);
                    if (selectedId.indexOf(select_node)>=0){
                        //选中节点
                        $('#jsTree_multi-select-tree_orgnization').jstree('select_node', select_node/* , true */);
                    }
                    currDeptId.splice(i, 1);
                    l = currDeptId.length
                }
            }
        }, 500);
    }
}

jstree选中节点与展开节点

© Copyright 2011-2019 adophper.com. All Rights Reserved.
读图网科技 版权所有。蜀ICP备12031064号