1
在rails 4.2.2中,我使用的是帶有上下文菜單選項的jstree
插件。現在,所有上下文菜單選項都顯示在文件和文件夾中。如何禁用根文件夾和其他特定文件夾的「刪除」選項?Rails 4 - jstree,如何禁用文件夾的「刪除」操作?
Script是,
<script type="text/javascript">
(function() {
var $j = jQuery.noConflict();
$j(document).ready(function() {
$j("#jstree").jstree({
"plugins": ["themes", "contextmenu", "dnd"],
"core" : {
themes: {"stripes": true},
check_callback : true,
animation : 0,
data : {
url: '/users/files/treedata.json'
}
},
contextmenu : {
"items" : function (node) {
return {
"view" : {
label: "View",
action: function(obj) {
window.open("https://stackoverflow.com/users/files/view/" + node.id);
}
},
"rename" : {
label: "Rename",
action: function(obj) {
$j("#jstree").jstree(true).edit(node)
}
},
"create" : {
label: "Create New",
action: function() {
createNode(node);
}
},
"delete" : {
label: "Delete",
action: function() {
if (confirm("Really delete " + node.text + "?")) {
deleteNode(node);
}
},
separator_before: true
}
}
}
}
});
$j("#jstree").on("move_node.jstree", function(event, data) {
moveNode(data);
});
$j("#jstree").on("rename_node.jstree", function(event, data) {
renameNode(data);
});
$j("#jstree").on("select_node.jstree", function(event, data) {
displayPath(data.node.id);
});
});
function moveNode(data) {
jQuery.ajax({
type: "GET",
url: "https://stackoverflow.com/users/home/move_node",
data: {id: data.node.id, parent: data.parent, old_parent: data.old_parent},
dataType : "script"
});
}
function renameNode(data) {
jQuery.ajax({
type: "GET",
url: "https://stackoverflow.com/users/home/rename_node",
data: {name: data.text, id: data.node.id, parent: data.node.parent},
dataType : "script"
});
}
function createNode(parent) {
jQuery.ajax({
type: "GET",
url: "https://stackoverflow.com/users/home/create_node",
data: {name: "New Folder", parent: parent.id},
dataType : "script"
});
}
function deleteNode(node) {
jQuery.ajax({
type: "GET",
url: "https://stackoverflow.com/users/home/delete_node",
data: {id: node.id, parent: node.parent},
dataType : "script"
});
}
function getPath(id) {
if (id == "#") {
return "";
}
return $j("#jstree").jstree(true).get_path({id: id}, "/");
}
function displayPath(nodeId) {
$j("#path").text("Path: /" + getPath(nodeId));
}
})();
</script>
請幫我完成了jstree disable
選項。而且在這裏,"select_node.jstree"
選項不起作用,我該如何解決這個問題?