jtree:如何将ajax加载的根节点的状态设置为待定状态

JStree: How to set state of AJAX-loaded root nodes to undetermined

本文关键字:状态 根节点 待定 设置 加载 ajax jtree      更新时间:2023-09-26

我使用jstree v3.0.2来显示具有三种状态复选框(已选中、未选中、未确定)的节点树,我通过AJAX调用以json格式加载这些复选框。只加载根节点,当用户扩展节点时,根据需要加载子节点。因此,我们还不知道节点的哪些子节点被(un)检查了,但是根节点必须被检查、未检查或未确定,这取决于底层的子节点。

我的问题与这个非常相似,希望这能使我的问题更容易理解,但这个问题似乎与旧版本有关,并且没有考虑节点的延迟加载。此外,最后一个答案建议使用"待定"状态似乎不起作用。

最初加载的JSON(对于最顶层的根节点)看起来像这样:

[{
    "id":"100",
    "parent":"#", // Indicates this is a topmost root node
    "text":"test1",
    "children":false, // Wether or not the node has children
    "state":{
        "selected":true, // Node is selected
        "partial_selection":false // Node state >should be< undetermined
    }
},{
    "id":"101",
    "parent":"#",
    "text":"test2",
    "children":true,
    "state":{
        "selected":true,
        "partial_selection":true
    }
},{
    "id":"102",
    "parent":"#",
    "text":"test3",
    "children":true,
    "state":{
        "selected":false
    }
}]
有人找到解决这个问题的方法了吗?

好的,我设法解决了这个问题。显然,jstree 确实接受'undetermined'-state(当使用最新版本的库时,在我的例子中是3.0.2),正如这个答案已经建议的那样,但是它只在'selected'-state被省略时工作(这是有意义的)。参考我在Github上提交的问题了解更多细节。