Customize the icons on the js tree


friends

I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes.

please help

Edit :

Tried adding the type plugin, but it doesn't seem to work.

  var data = {
      'core': {
          'data': dataObj
      },
      "search": {
          "case_insensitive": true,
          "show_only_matches": true
      },
      "plugins": ["search", "themes"]
  };
  $('#jstree_category').jstree(data);
  $('#jstree_category').on("loaded.jstree", function (e, data) {
      _this.treeLoaded = true;
      if (!_this.dataFetched) {
          return;
      }
  });
   // bind customize icon change function in jsTree open_node event.
  $('#jstree_category').on('open_node.jstree', function (e, data) {
      $('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first()
          .removeClass('glyphicon glyphicon-folder-close').addClass('glyphicon glyphicon-folder-open');
      $('#' + data.node.id).find('i.jstree-icon.jstree-themeicon')
          .addClass('glyphicon glyphicon-leaf');
  });
   // bind customize icon change function in jsTree close_node event.
  $('#jstree_category').on('close_node.jstree', function (e, data) {
      $('#' + data.node.id).find('i.jstree-icon.jstree-themeicon').first()
          .removeClass('glyphicon glyphicon-folder-open').addClass('glyphicon glyphicon-folder-close');
      $('#' + data.node.id).find('i.jstree-icon.jstree-themeicon')
          .addClass('glyphicon glyphicon-leaf');
  });

enter image description here

stargazer

Here is the fiddle that works for you. You should mention the type of node in JSON dataObj.

var jsonData = [
  {
    id  : 1,
    text : "Folder 1",
    type: "root",
    state : {
      selected  : false
    },
    children    : [
      {
        id  : 2,
        text : "Sub Folder 1",
        type: "child",
        state : {
          selected  : false
        },  
      },
      {
        id  : 3,
        text : "Sub Folder 2",
        type: "child",
        state : {
          selected  : false
        },  
      }
    ]
  }, 
  {
    id: 4,
    text : "Folder 2",
    type: "root",
    state : {
      selected : true
    },
    children : []
  }
];

$('#jstree-tree')
  .jstree({
  core: {
    data: jsonData
  },
  types: {
    "root": {
      "icon" : "glyphicon glyphicon-plus"
    },
    "child": {
      "icon" : "glyphicon glyphicon-leaf"
    },
    "default" : {
    }
  },
  plugins: ["search", "themes", "types"]
}).on('open_node.jstree', function (e, data) { data.instance.set_icon(data.node, "glyphicon glyphicon-minus"); 
}).on('close_node.jstree', function (e, data) { data.instance.set_icon(data.node, "glyphicon glyphicon-plus"); });

JSFiddle

Related


Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize the icons on the js tree

friends I want to add a folder open close icon for closing and expanding, and a leaf icon for leaf nodes. please help Edit : Tried adding the type plugin, but it doesn't seem to work. var data = { 'core': { 'data': dataObj }, "sea

Customize parsley.js to display icons near offending fields

Luciano Fiandesio I want parsley.js to display an icon near the label of each field in question. It's just like: <label class="warning" for="name">Name</label> (http://jsfiddle.net/7q3ktchb/) Essentially, I want to configure parsley to set the class of the of

Customize file types and icons

Becky: 我有一个用Java编写的游戏,它具有保存游戏并加载所有使用.txt文件的功能,但是我认为如果我可以拥有自己的文件类型,那就太酷了……我知道我可以将其设置为另存为尚未定义的类型,但随后我得到该文件的空白图标...是否可以在Java中为其提供自定义文件图标?我看过在线等,但我发现的只是Microsoft网站在c#和vb等中解释了其中的一些... 詹姆斯·坎贝尔: 我想,如果您在Windows中创建了文件类型(如果您在Windows中),则可以将文件类型添加到系统中。然后查看现有文件类型。现在,将您的图标关

Customize icons in grub theme

nt First of all, I don't know if this is the right place to post, so sorry if it's not. I have installed the theme ( tela ) in the grub bootloader and added the icon to the OS entry. Is there any way to manually assign icons to entries? For example, the Linux

How to customize location icons?

Emil Balley I'm trying to replace the location icon in the demo with my own, but I haven't figured out how to do it yet. I searched for its declaration in the .json file without success. { "class" : "map", "colortype" : "rgba", "columns

Customize Installer Icons with NSIS

soak I am using NSIS to create an installer. The output file installer.exe now has a standard icon that can be found at: {NSIS_Install_Dir}\Contrib\Graphics\Icons\classic-install.ico I want to use custom mines to change it, so in the documentation I suggest a

How to Customize Special Icons

christian 007 I'm evaluating Install4j to see if I can replace InstallAnywhere. Custom Installer/Unistaller's icon [executable icon] is clear to me. The possibility to customize the image in the title bar is also evident. I'm asking if I also have customizatio

Customize file types and icons

Becky: I have a game written in Java that has the ability to save the game and load everything using a .txt file, but I thought it would be cool if I could have my own file type...I know I can set it as Save as a not yet defined type, but then I get a blank ic

Customize icons in grub theme

nt First of all, I don't know if this is the right place to post, so sorry if it's not. I have installed the theme ( tela ) in the grub bootloader and added the icon to the OS entry. Is there any way to manually assign icons to entries? For example, the Linux

How to customize location icons?

Emil Balley I'm trying to replace the location icon in the demo with my own, but I haven't figured out how to do it yet. I searched for its declaration in the .json file without success. { "class" : "map", "colortype" : "rgba", "columns

Customize Installer Icons with NSIS

soak I am using NSIS to create an installer. The output file installer.exe now has a standard icon that can be found at: {NSIS_Install_Dir}\Contrib\Graphics\Icons\classic-install.ico I want to use custom mines to change it, so in the documentation I suggest a

Customize Installer Icons with NSIS

soak I am using NSIS to create an installer. The output file installer.exe now has a standard icon that can be found at: {NSIS_Install_Dir}\Contrib\Graphics\Icons\classic-install.ico I want to use custom mines to change it, so in the documentation I suggest a

Customize Installer Icons with NSIS

soak I am using NSIS to create an installer. The output file installer.exe now has a standard icon that can be found at: {NSIS_Install_Dir}\Contrib\Graphics\Icons\classic-install.ico I want to use custom mines to change it, so in the documentation I suggest a

How to Customize Condition Icons

Arthur I want to customize icon standard. I need 5 conditions. I used IconSetCondition. requirement is: value < 0.85 value < 0.95 Value < 1.06 Value < 1.15 value >= 1.15 I want to use 3Traffic lights in this way: value <0.85 -> "red traffic light" value < 0.95

How to Customize Special Icons

christian 007 I'm evaluating Install4j to see if I can replace InstallAnywhere. Custom Installer/Unistaller's icon [executable icon] is clear to me. The possibility to customize the image in the title bar is also evident. I'm asking if I also have customizatio

Customize file types and icons

Becky: I have a game written in Java that has the ability to save the game and load everything using a .txt file, but I thought it would be cool if I could have my own file type...I know I can set it as Save as a not yet defined type, but then I get a blank ic

Customize icons in grub theme

nt First of all, I don't know if this is the right place to post, so sorry if it's not. I have installed the theme ( tela ) in the grub bootloader and added the icon to the OS entry. Is there any way to manually assign icons to entries? For example, the Linux