如果父节点已经拥有名称为“ New Node”的jsTree子节点,反之亦然

时间:2019-05-31 05:53:48

标签: jquery json jstree jstree-dnd jstree-search

默认情况下,当我创建父节点(“文档”)的新实例(子节点)时,其名称为“新节点”。同样,如果我尝试为同一父级创建新节点,则默认情况下会创建名称为“ New node 2”的子节点。现在,如果我尝试为现有子节点(例如“新节点2”)创建子节点,则不会创建该子节点。我正在使用mysql表保存ID为主键的节点名称。

在最初创建子节点时,我尝试创建2个子节点(例如“ PDF”和“ EXCEL”),然后尝试在“ PDF”中创建另一个名为“ EXCEL”的子节点。现在,在这种情况下,默认情况下将其保存为新名称“ New node”。

function buildCareDocumentTree(){
    var id = $("#userId").val();
    $("#jstreeContainer").jstree({
        "core":{
            "check_callback": true,
            'data': {
                'url': function(node){
                    return '${pageContext.request.contextPath}/user/documents/folders/children/'+id;
                }, 
                'data': function(node){
                    console.log(node);
                    return /* { 'id' : node.id,"parent" : node.parent, "text" : node.name } */; 
                },
                'children': true,
            },
        }, // so that operations work
        'contextmenu': {
            'items': function(node){
                var tmp = $.jstree.defaults.contextmenu.items();
                delete tmp.create.action;
                tmp.create.label = "New";
                 tmp.create.submenu = {
                    "create_folder": {
                        "separator_after": true,
                        "label": "Folder",
                        "action": function(data) {
                            var inst = $.jstree.reference(data.reference),
                                obj = inst.get_node(data.reference);
                            inst.create_node(obj, {
                                type: "default"
                            }, "last", function(new_node) {
                                setTimeout(function() {
                                    inst.edit(new_node);
                                }, 0);
                            });
                        }
                    },
                    "create_file": {
                        "label": "File",
                        "action": function(data) {
                            $('#md-addDocument').addClass('modal-show');
                            $('#documentForm').parsley().destroy();
                            $('#documentForm')[0].reset();
                        }
                    }
                };

0 个答案:

没有答案
相关问题