how to deny delete/rename/move root(or other) node(s) in jsTree?

偶尔善良 提交于 2019-12-11 05:26:49

问题


for example:

[{
"data": "reference",
"attr": {
    "id": "0"
},
"state": "open",
"children": [
    [{
        "data": "one",
        "attr": {
            "id": "1"
        },
        "state": "closed"
    }, {
        "data": "two",
        "attr": {
            "id": "2"
        }
    }]
]
}, {
"data": "recycle bin",
"attr": {
    "id": "bin"
},
"state": "closed",
"children": []
}]

i need to deny delete/move/rename "reference" & "recycle bin" nodes with "dnd", "crrm" and "context menu" plugins


回答1:


For avoiding moves using the crrm plugin you could do:

"crrm": {
   "move": {
      "check_move": function(m) { return (m.o[0].id !== "0" && m.o[0].id !== "bin"); }
   }
}

In summary, you need to return TRUE for allowing the move, or FALSE otherwise. So you check that the node's ID being moved is not the reference one, or the recycle bin one.

Please take a look at the jsTree documentation for accomplishing the other tasks, as everything you need is there. Don't be lazy :-)




回答2:


You can capture node delete event and check for node's metadata:

.bind('delete_node.jstree', function (e, data) {
    // Check medatada, assuming that root's parent_id is NULL:
    if (data.rslt.obj.attr('parent_id') == null) {
       alert('Root folder is here to stay.');
       e.stopImmediatePropagation();
       return false;
    }
})


来源:https://stackoverflow.com/questions/9836942/how-to-deny-delete-rename-move-rootor-other-nodes-in-jstree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!