jstree,禁用文件节点

时间:2012-06-14 08:32:44

标签: javascript jquery jstree

如何禁用文件节点,以便树只显示文件夹而不显示文件,这是我目前的代码,

$(document).ready(function () {

//$("#MySplitter").splitter();
setupSplitter();


$("#divJsTreeDemo").bind("select_node.jstree", function (e, data) {
    //        if (document.location.href != data.rslt.obj.children("a").attr("href")) {
    //            document.location.href = data.rslt.obj.children("a").attr("href");
    //  

    var id = data.rslt.obj.attr("id").replace("node", "");

    //        var tree = jQuery.jstree._reference("#divJsTreeDemo");
    //        var currentNode = tree._get_node(null, false);
    //        tree.refresh(currentNode);

    GetChildObjects(id);

}).delegate("a", "click", function (e) {


    //$("#divJsTreeDemo").jstree("toggle_node", this);


}).jstree({
    "themes": {
        "theme": "default",
        "dots": false,
        "icons": false
    },
    "plugins": [
           "core", "themes", "json_data", "types", "ui"
    ],
    "types": {
        // I set both options to -2, as I do not need depth and children count checking
        // Those two checks may slow jstree a lot, so use only when needed
        "max_depth": -2,
        "max_children": -2,
        // I want only `drive` nodes to be root nodes 
        // This will prevent moving or creating any other type as a root node
        "valid_children": ["drive"],
        "types": {
            // The default type
            "default": {
                // I want this type to have no children (so only leaf nodes)
                // In my case - those are files
                "valid_children": "none",
                // If we specify an icon for the default type it WILL OVERRIDE the theme icons
                "icon": {
                    "image": "../../Repository/Images/file.png"
                }
            },
            // The `folder` type
            "folder": {
                // can have files and other folders inside of it, but NOT `drive` nodes
                "valid_children": ["default", "folder"],
                "icon": {
                    "image": "../../Repository/Images/folder.png"
                }
            }
        }
    },
    "json_data": {
        "ajax": {
            "type": "POST",
            "url": "GetTreeNodes",
            "data": function (n) {
                return { id: n.attr ? n.attr("id").replace("node", "") : 0 };
            },
            "async": true,
            "success": function (data) {

                RenderFileFolder(data);

            }
        }
    }

});

});

0 个答案:

没有答案