问题
I have a jsTree, built dynamically, that allows the user to select whatever nodes he chooses.
Now i'm trying to make this tree readonly so that other users can see the information without altering it.
All examples i find are about disabling a specific node...
My question is: Is there a way to define all the checkboxes on the tree to readonly?
Code being used:
jQuery.noConflict();
jQuery(
function() {
jQuery("#divTree").jstree(
{
"plugins": ["themes", "json_data", "checkbox", "sort", "ui", "real_checkboxes"],
json_data: { data: data }
}
);
}
);
回答1:
Problem Solved. Here is the solution for anyone that needs it.
jQuery.noConflict();
jQuery(
function() {
jQuery("#divTree")
<% if(isReadOnly) { %>
.bind("loaded.jstree", function (event, data)
{
jQuery('.jstree a').click(function() {return false;});
})
<% } %>
.jstree(
{
"plugins": ["themes", "json_data", "checkbox", "sort", "ui", "real_checkboxes"],
json_data: { data: data }
}
);
}
);
回答2:
You can define this in your default type
, or define your own type
for specific nodes then bind them to it:
jQuery("#divTree").jstree({
"types": {
"default": {
"check_node": false,
"uncheck_node": false
}
},
"plugins": ["themes", "json_data", "checkbox", "sort", "ui", "real_checkboxes"],
"json_data": { data: data }
});
If I were you, I'd just wrap that types
declaration inside a server side if
statement to determine whether you want this tree to be read only or not.
Docs: http://www.jstree.com/documentation/types
来源:https://stackoverflow.com/questions/20491989/having-a-jstree-with-checkboxes-how-can-i-disable-all-checkboxes