jstree使用示例代碼


首先定義一個展示樹的div
<div id="twDept" class="tree-demo"></div>
 
  //初始化樹
        function initTree() {
            $('#twDept').jstree({
                "core": {
                    "themes": {
                        "responsive": false
                    },
                    'check_callback': true,
                    'data': function (obj, callback) {
                        report.DataGet('查詢1級部門的接口路徑', null, function (data) {
                            if (data) {
                                callback.call(this, data);
                            }
                        }, null, 'json');
                    }
                },
                "types": {
                    "default": {
                        "icon": "fa fa-folder icon-state-warning icon-lg"
                    },
                    "file": {
                        "icon": "fa fa-file icon-state-warning icon-lg"
                    }
                },
                "plugins": ["types", "checkbox"],
                "checkbox": {
                    "keep_selected_style": false,//是否默認選中
                    "three_state": false//父子級別級聯選擇
                }
            });
            $('#twDept').on("loaded.jstree", function (e, data) {
                var root = e.target.firstChild.firstChild;
                data.instance.open_node(root);
                _inst = data.instance;
            });
            $('#twDept').on("open_node.jstree", function (e, data) {
                var inst = data.instance;
                var selectedNode = inst.get_node(data.node);
                var firChild = $('#twDept').jstree("get_node", inst.get_children_dom(selectedNode)[0].id);
                if (firChild.text == "" && selectedNode.id != e.target.firstChild.firstChild.id) {
                    selectedNode.children = [];
                    report.DataGet('查詢子節點的接口路徑'?code=' + selectedNode.li_attr.treeDeptCode, null, function (data) {
                        if (data) {
                            $.each(data, function (i, item) {
                                inst.create_node(selectedNode, item, "last");
                            })
                        }
                    }, null, 'json');
                }
            });
            //end new
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM