多树之间的Jstree Valid_children

时间:2014-07-14 03:36:50

标签: jquery types jstree

我目前有2个jstrees都使用Types插件来定义每个节点的类型。我的问题是,当我将一个节点从jstree#1,类型为“Topic”拖到另一个树jstree#2,其节点类型为“Folder”时,它只给我一个红色的X.我的类型为“Folder”,用< b> jstree#2上的“valid_children”:“主题”

jstree#1工具箱。用于将某些节点拖到另一个节点中。 “Always_copy”

.jstree({
    "core": {
        //Prevent node from being deleted when moved to the design tree
        "check_callback": function (operation, node, node_parent, node_position, more) {

        },
        "data": {
            "url": getToolTreeUrl,
            "data": function (node) {
                return { 'id': node.id };
            }
        }
    },
    //Enabled the drag and drop plugin with ability to drag and drop between tree
    "plugins": ["dnd", "unique", "types", "ccrm"],
    "crrm": {
        "move": {
            "check_copy": function () {
                alert("Check_Copy");
            },
        },
    },
    "types": {
        "#": {
            "max_children": 1,
            "max_depth": 2
        },
        "Topic": {
            "valid_children": "Task"
        },
        "Task": {
            "valid_children": "Task"
        },
        "Paragraph": {

        },
        "Dictionary_List": {

        },
        "Ordered_List": {

        },
        "Unordered_List": {

        },
        "List_Item": {

        },
        "Picture": {

        },
        "Video": {

        },
        "Table": {

        },
        "Note": {

        },
        "QHSE-Note": {

        },
    },
    "dnd": {
        always_copy: true,
        is_draggable: function (data) {
            return data[0].id != 0; //disallow entire toolbox being dragged
        },
    },
    rules: {
        multitree: true,
        draggable: "all"
    }
});

}

jstree#2是我的文档,它从工具箱中接收节点。

.jstree({
    "core": {
        "check_callback": function (operation, node, node_parent, node_position, more) {
            var type = node.text;
            var parentValue = node.parent;

            if (operation == "move_node") {
                asyncPost(getObjectLogicCheckUrl);
            }
            if (operation == "copy_node") {
                asyncPost(getObjectLogicCheckUrl);
            }
        },
        "data": data
    },
    "plugins": ["dnd", "contextmenu", "types"], contextmenu: { items: customMenu },
    "crrm": {
        "move": {
            "check_copy": function () {
                alert("Check_Copy");
            },
        },  
    },
    "types": {
        "#": {
            "max_children": 1
       },
       "Topic": {
           //"valid_children": "Task"
       },
       "Task": {
           //"valid_children": ["Task", "Paragraph", "Dictionary_List", "Ordered_List", "Unordered_List", "Picture", "Video", "Table", "Note", "QHSE-Note"],
       },
       "Paragraph": {
           //"valid_children": ["Paragraph", "Dictionary_List", "Ordered_List", "Unordered_List", "Picture", "Video", "Table", "Note", "QHSE-Note"]
       },
       "Dictionary_List": {
           "valid_children": ["List_Item"]
       },
       "Ordered_List": {
           "valid_children": ["List_Item"]
       },
       "Unordered_List": {
           "valid_children": ["List_Item"]
       },
       "List_Item": {
           "max_children": 0
       },
       "Picture": {
           "max_children": 0
       },
       "Video": {
           "max_children": 0
       },
       "Table": {
           "max_children": 0
       },
       "Note": {

       },
       "QHSE-Note": {

       },
       "Folder": {
           "valid_children": "Topic"
       },
    },
    rules: {
        multitree: true,
        draggable: "all",
    },

我试图找出一种方法来锁定哪些节点可以拖到文档树中的哪个位置。 IE ..类型为“Topic”的节点只能接受类型为“Task”的节点。

如果有人知道如何启用Types插件在多个树之间工作,请帮助。

1 个答案:

答案 0 :(得分:0)

我明白了。两个树节点都需要应用相同的规则才能工作。

jstree#1

"Topic": {
       "valid_children": "Task"
   },

jstree#2

"Topic": {
       "valid_children": "Task"
   },