How to change icon in jstree?

后端 未结 10 1911
心在旅途
心在旅途 2021-02-01 16:25

I have the following code:

$(\'.wpFolders.co_files\').bind(\'select_node.jstree\', function (event, data) {
            getFileById(data.args[0].hash.replace(\'#         


        
相关标签:
10条回答
  • 2021-02-01 16:28

    To hide the folder icon use the following:

    <style type="text/css">
     .jstree li > a > .jstree-icon {  display:none !important; } 
    </style>
    
    0 讨论(0)
  • 2021-02-01 16:28

    The following script works for me:

    $('div#jstree').on('ready.jstree click', function (e, data) {
            $('i.jstree-icon').removeClass('jstree-themeicon jstree-icon').addClass('fa fa-lg fa-user');
        });
    
    0 讨论(0)
  • 2021-02-01 16:29

    After an headache... I found a solution.

    
        <li data-jstree='{"icon":"path/file.png"}'></li>
    
    

    I suggest to don't modify the css code.

    PS The "types" plug-in is not necessary.

    0 讨论(0)
  • 2021-02-01 16:35

    Two problems:

    1. I needed to add the "type" in my rel attribute of my list objects (I created a default and file type).
    2. I forgot one level in my array declaring the types, the code had to be like the following:

      $('.wpFolders.co_files').bind('select_node.jstree', function (event, data) {
          getFileById(data.args[0].hash.replace('#', ''));
      }).jstree({
          'plugins' : ['html_data','themes','ui','types'],
          'ui' : {
              'select_limit' : 1
          },
          'core' : {
              'animation' : 0
          },
          'types': {
              'types' : {
                  'file' : {
                      'icon' : {
                          'image' : '/admin/views/images/file.png'
                      }
                  },
                  'default' : {
                      'icon' : {
                          'image' : '/admin/views/images/file.png'
                      },
                      'valid_children' : 'default'
                  }
              }
      
          }
      });
      

    I don't really understand why my code is breaking in the WYSIWYG, sorry if it's ugly. Anyway, I hope this can help someone.

    0 讨论(0)
  • 2021-02-01 16:40

    You may change the icon with the new API, without HTML, CSS, or plugins.

    $("#tree").jstree(true).set_icon(nodeId, "/images/blabla.png");
    
    0 讨论(0)
  • 2021-02-01 16:43

    jstree includes its own file icon (in addition to the default folder icon), add 'icon': 'jstree-file' property to node to show it

    0 讨论(0)
提交回复
热议问题