jstree.js切换图标样式

实际效果如下:


主要代码如下:

 1 rendertree: function () {
 2     $('#lazy')
 3     .jstree({
 4         "themes": {
 5             "stripes": true,
 6         },
 7         "types": {
 8             "default" : {
 9                 "icon": "fa fa-user"
10             },
11             'nouser': {
12                 "icon": 'fa fa-user-o'
13             }
14         },
15         "plugins": ["changed", "types"],
16         'core' : {
17             "data": {
18                 "url": 'agent/agent/index/',
19                 // "type": 'get',
20                 "data": function (content) {
21                     return { "agentid": content.id };
22                 },
23             }
24         }
25     }).on("load_node.jstree",function(e,d){
26         // console.log(e)
27         // console.log(d)
28         var nodes = d.node.children_d;
29         for(var i in nodes){
30             var node = d.instance.get_node(nodes[i]);
31             if( !node.original.haschild ){
32                 // d.instance.set_icon(node, 'nouser'); //nouser此处为class
33                 d.instance.set_type(node, 'nouser');
34             }
35         }
36     });
37 
38 },

源码(jstree.js)中修改:(需要返回haschild属性字段)

原文地址:https://www.cnblogs.com/linka/p/7639724.html