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

发布于 2024-12-23 06:14:57 字数 1026 浏览 2 评论 0原文

基本上,我有一个 jsTree,我需要通过添加自定义类来格式化它的 lia 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
                }
            });

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
                }
            });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿挽旧人 2024-12-30 06:14:57

如果您想在 JSON 响应中执行此操作,这对我有用:

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

第一个 attr 引用

  • 标记,第二个 attr< /strong>(内部数据)指的是 标签。
  • 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.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文