Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将自定义类添加到jstree_Php_Css_Html_Jquery Plugins_Jstree - Fatal编程技术网

Php 将自定义类添加到jstree

Php 将自定义类添加到jstree,php,css,html,jquery-plugins,jstree,Php,Css,Html,Jquery Plugins,Jstree,我需要向jstree中的所有子节点和父节点添加一个类 尝试了下面的代码,但不起作用 $('#data').jstree({ 'core' : { 'data' : [{"text" : "GROUPS","state":{"opened":true}, "children" : [{ "text" : "USERS", attributes : { class : "desired_node_class" }}

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

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

$('#data').jstree({
        'core' : {
            'data' : [{"text" : "GROUPS","state":{"opened":true}, 
                      "children" : [{ "text" : "USERS", attributes : { class : "desired_node_class" }},{ "text" : "ADMIN"}]}                    
            ]
        }
    });
我做错了什么?。 这是一把小提琴

有人能纠正我吗

提前谢谢

试试这个:

element.classList.add("desired_node_class");

您需要在JSON中使用文档中指定的
li_attr
而不是
attr
。这是你最新的小提琴:

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

顺便说一句,如果您只是尝试为某些内容设置样式,那么最好不要添加自定义类,而是使用每个节点上已有的CSS类:

#data .jstree-node { } /* this is for each LI node */
#data .jstree-anchor { } /* this is for each A node */

向DOM元素添加类与向jstree节点添加类无关。