禁用 jstree 节点

发布于 2024-12-19 00:47:41 字数 147 浏览 7 评论 0原文

我从 struts2 生成 jstree,从数据库生成 JSON。从数据库中,我有一个标志告诉我活动和禁用,所以请有人帮助我如何根据此禁用 jstree 节点。 谷歌之后,我发现可以通过“类型”插入来实现,但我无法理解如何使用类型插件。如果有任何可用的示例,那么它对我非常有帮助。

I am generating jstree from struts2 and JSON from database. From DB I have one flag which tell me active and disable, so can you please somebody help me how to disable a jstree node according to this.
After google I find that it is possible by "type" pluging but I cant understand how to use type plugin for this.If any example available then it is very helpful for me.

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

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

发布评论

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

评论(1

掩饰不了的爱 2024-12-26 00:47:41

看看我的另一个答案,因为你需要它:

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

基本上,你要做什么需要的是像现在一样在后端构建 JSON,并且因为您知道需要禁用(或样式化)哪些节点,所以您可以设置不同的 CSS 类名称或不同的属性,例如 class=此 JSON 响应中的“disabled”rel="disabled" 如链接所示。

我不知道您需要在这些节点中完成什么级别的自定义,但是对它们进行样式设置足以更改字体和背景。

然后,正如您所说,您可以使用 类型插件 来自定义这些“禁用”的行为节点,即

types: {
    "disabled": {
        "select_node": false,
        "open_node":   false,
        "close_node":  false,
        "create_node": false,
        "delete_node": false
    }
}

注意我们定义了类型并将其命名为“disabled”,因此您需要在每个

  • 元素(节点)中放置一个 rel="disabled"你想禁用。这就是 jsTree 默认情况下使用 rel 属性 寻找类型的方式。
  • 我希望这对你有帮助。

    Take a look at this other answer by me as you will need it:

    How do you format "li" and "a" DOM elements in jsTree by setting their class?

    Basically, what you need is to build the JSON as you are doing now, in the backend, and because you know which nodes need to be disabled (or styled) you can set different CSS class names or different attributes like, for example, class="disabled" or rel="disabled" in this JSON response as shown in the link.

    I don´t know what level of customization you need to accomplish in those nodes, but styling them would be enough to change font and background.

    Then, as you said, you can use the Types plugin to customize behaviour of these "disabled" nodes, i.e.

    types: {
        "disabled": {
            "select_node": false,
            "open_node":   false,
            "close_node":  false,
            "create_node": false,
            "delete_node": false
        }
    }
    

    Note we defined the Type and named it "disabled" so you will need to put a rel="disabled" in each <li> element (node) you want to disable. This is how jsTree seek for types by default, using the rel attribute.

    I hope this helps you.

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