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級部門的接口路徑'nullfunction (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, nullfunction (data) {
                        if (data) {
                            $.each(data, function (i, item) {
                                inst.create_node(selectedNode, item, "last");
                            })
                        }
                    }, null'json');
                }
            });
            //end new
        }
相關文章
相關標籤/搜索