问题
Basically, I have a jsTree, and I need to format it's li and a DOM elements by adding custom class to each type. The documentation is not clear on how to do this and as far as I can tell, there is no way to add custom class, any formating will have to be by overriding jquery theme or by editng the jsTree source-code. I am ok with either doing it in the JSON data, or more effectively, when declaring the "types" as shown in the example here:
$("#container").jstree({
"plugins" : ["themes", "json_data", "ui", "themeroller", "types"],
"json_data" : {"data": my_json_data},
"core" : {
"initially_select" : [ init_id]
},
"types" : {
"valid_children" : [ "test_type" ],
"types" : {
"test_type" : {
"valid_children" : [ "default", "test_type" ],
"icon" : { "image" : "/includes/icon.gif"}
}
}
},
"themes" : {
"dots" : true,
"icons" : true
}
});
回答1:
If you want to do it in the JSON response, this works for me:
{
"attr": { "class": "some-class1", "id": "node_1" },
"data": {
"attr": { "class": "some-class2", "href": "", "title": "node title" }
}
}
The first attr refers to the <li>
tag, and the second attr (inside data) refers to the <a>
tag.
来源:https://stackoverflow.com/questions/8652276/how-do-you-format-li-and-a-dom-elements-in-jstree-by-setting-their-class