将自定义类添加到 jstree

Swa*_*nde 5 html css php jquery-plugins jstree

我需要向 jstree 中的所有子节点和父节点添加一个类。

尝试了下面的代码,但它不起作用。

$('#data').jstree({
        'core' : {
            'data' : [{"text" : "GROUPS","state":{"opened":true}, 
                      "children" : [{ "text" : "USERS", attributes : { class : "desired_node_class" }},{ "text" : "ADMIN"}]}                    
            ]
        }
    });
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?。这是一个小提琴 http://jsfiddle.net/m6yxhnrg/

有人可以纠正我吗

提前致谢!

vak*_*ata 8

您需要在文档中指定的 JSON 中使用li_attrnot attr。这是您更新的小提琴:http : //jsfiddle.net/m6yxhnrg/1/

我按照您的要求向所有节点添加了类 - 您必须包含每个节点的类数据。

顺便说一下,如果你只是想设置一些样式,最好跳过添加自定义类并使用现有的 CSS 类,这些类已经在每个节点上可用:

#data .jstree-node { } /* this is for each LI node */
#data .jstree-anchor { } /* this is for each A node */
Run Code Online (Sandbox Code Playgroud)