javascript - jstree select_node.jstree 未触发

标签 javascript jquery jstree

我正在使用 jstree 并且 select_node.jstree 不会触发,这是代码

$(document).ready(function () {

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


$("#divJsTreeDemo").jstree({
    "themes": {
        "theme": "default",
        "dots": false,
        "icons": false
    },
    "plugins": [
            "core", "themes", "json_data", "ui", "types"
    ],
    "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) {


                var myJSONText = JSON.stringify({ id: n.attr ? n.attr("id").replace("node", "") : 0 }, replacer);

                return { id: n.attr ? n.attr("id").replace("node", "") : 0 };

            },
            "success": function (data) {

                $(".folder-file-container").remove();

                RenderFileFolder(data);



            }
        }
        //            "data": {
        //                // `data` can also be an object
        //                "data": {
        //                    "title": "The node title",
        //                    // omit when not needed
        //                    "attr": {},
        //                    // if `icon` contains a slash / it is treated as a file, used for background
        //                    // otherwise - it is added as a class to the <ins> node
        //                    "icon": "../../Repository/Images/pdf.png"
        //                },
        //                // the `metadata` property will be saved using the jQuery `data` function on the `li` node
        //            }
    }

}).bind("select_node.jstree", function (e, data) { 

    alert(data.rslt.obj.data("id")); 



});

});

最佳答案

试试这个:

    .bind("select_node.jstree", function (e, data) {
        var a = $.jstree._focused().get_selected();
        alert(a);
    }

(取自 jstree select node )。

关于javascript - jstree select_node.jstree 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11010866/

相关文章:

javascript - 基于单选按钮的启用或禁用按钮在 jQuery 中不起作用?

javascript - 使用 jquery 通过方法选择 javascript 对象

javascript - 在 jsTree 中,使节点文本可点击的最佳方法是什么(用于选中复选框)

javascript - 使用 Node.js 从 API 填充数据

javascript - ajax 返回 true,但 == 返回 false

javascript - 如何在 Angular View 中用空格 (' ' ) 替换下划线 (_)?

javascript - CasperJS 和 mint.com

javascript - 如何在数组前使用带有额外参数的 JavaScript 的 "apply"方法?

jquery - Jstree中如何通过ID获取节点

javascript - jstree 图标以及如何 'click to expand'