如何通过设置类来格式化jsTree中的“li”和“a”DOM元素?

基本上,我有一个jsTree,我需要通过为每种类型添加自定义类来格式化它的li和DOM元素。 文档不清楚如何做到这一点,据我所知,没有办法添加自定义类,任何格式化都必须通过重写jquery主题或编辑jsTree源代码。 我可以在JSON数据中执行此操作,或者在声明此类示例中显示的“类型”时更有效:

$("#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 } }); 

如果你想在JSON响应中这样做,这对我有用:

 { "attr": { "class": "some-class1", "id": "node_1" }, "data": { "attr": { "class": "some-class2", "href": "", "title": "node title" } } } 

第一个attr引用

  • 标签,第二个attr (内部数据)引用标签。