It's easy to specify what the icon should be for a closed folder using the "types" plugin. But can the types plugin also be used to specify what an open folder should look like, or can I only do this with CSS (like below) ?
li.jstree-open > a .jstree-icon
{
background:url("folder_open.png") 0px 0px no-repeat !important;
}
A possible solution is to have two type
s - one for an open folder, and one for a closed folder. Changing the node type
is easy.
From another answer of mine :
<div id="jstree_menu"></div>
<script>
/* Load menu tree data */
$('#jstree_menu').jstree(
{
'core' : {
'data' : {
'url' : '/jstree-menu-data/index.html',
}
},
'plugins' : [ "types" ],
'types' : {
'default' : {
'icon' : 'fa fa-angle-right fa-fw'
},
'f-open' : {
'icon' : 'fa fa-folder-open fa-fw'
},
'f-closed' : {
'icon' : 'fa fa-folder fa-fw'
}
}
}
);
/* Toggle between folder open and folder closed */
$("#jstree_menu").on('open_node.jstree', function (event, data) {
data.instance.set_type(data.node,'f-open');
});
$("#jstree_menu").on('close_node.jstree', function (event, data) {
data.instance.set_type(data.node,'f-closed');
});
</script>
@Seventh element:
Your code in the question itself is the answer.It works pretty fine. For open node use
li.jstree-open > a .jstree-icon { background:url("/images/favorites.png") 0px 0px no-repeat !important; }
For closed nodes use
li.jstree-closed > a .jstree-icon { background:url("/images/favorites.png") 0px 0px no-repeat !important; }
Cheers
If you guys want to use jQuery and bootstrap icon, here is my solution.
[Note: I use glyphicon-folder-open bootstrap icon for folder open and glyphicon-folder-close bootstrap icon for folder close.]
// bind customize icon change function in jsTree open_node event.
$('#your-jstree').on('open_node.jstree', function(e, data){
$('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first()
.removeClass('glyphicon-folder-close').addClass('glyphicon-folder-open');
});
// bind customize icon change function in jsTree close_node event.
$('#your-jstree').on('close_node.jstree', function(e, data){
$('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first()
.removeClass('glyphicon-folder-open').addClass('glyphicon-folder-close');
});
or if you are using font-awesome:
// bind customize icon change function in jsTree open_node event.
$('#jstree').on('open_node.jstree', function(e, data){
var icon = $('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first();
icon.removeClass('fa-folder').addClass('fa-folder-open');
});
// bind customize icon change function in jsTree close_node event.
$('#jstree').on('close_node.jstree', function(e, data){
var icon = $('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first();
icon.removeClass('fa-folder-open').addClass('fa-folder');
});
今天,有一个名为“set_icon”的函数(参见API ),它允许您从路径字符串或类名设置desider图标。
$.jstree.reference('#jstree').set_icon(node, "/assets/contextMenu_icons/folderOpened.png")
Looks like you need to use css
li.jstree-open[rel=TYPE]{ background:url("openimage.gif") 0px 0px no-repeat !important; }
li.jstree-closed[rel=TYPE]{ background:url("closedimage.gif") 0px 0px no-repeat !important; }
li.jstree-leaf[rel=TYPE]{ background:url("leafimage.gif") 0px 0px no-repeat !important; }
more info in the jsTree forum
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.