[英]JStree: How to set state of AJAX-loaded root nodes to undetermined
I'm using jstree v3.0.2 to display a tree of nodes with three-state checkboxes (checked, unchecked, undetermined), which I load in JSON-format through an AJAX call. 我正在使用jstree v3.0.2来显示带有三态复选框(选中,未选中,不确定)的节点树,该复选框通过AJAX调用以JSON格式加载。 Only the root nodes are loaded, the children are loaded on demand when the user expands a node. 当用户扩展节点时,仅根节点被加载,子节点按需加载。 Therefore, we don't know yet which children of a node are (un)checked, but the root node has to be checked, unchecked or undetermined depending on the underlying children. 因此,我们尚不知道(未)检查节点的哪些子节点,但是根节点必须根据基础子节点进行检查,未检查或不确定。
My question is very similar to this one , which hopefully makes my problem more understandeable, but that one seemingly relates to an older version and doesn't account for lazy-loading of nodes. 我的问题与这一问题非常相似,希望可以使我的问题更容易理解,但该问题似乎与较旧的版本有关,并且不考虑节点的延迟加载。 Also, the last answer which suggests using the "undetermined" state doesn't seem to work. 同样, 最后一个建议使用“不确定”状态的答案似乎不起作用。
The JSON which is initially loaded (for the topmost root nodes) looks like this: 最初加载的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
}
}]
Has anyone found out a solution to this problem? 有没有人找到解决这个问题的方法?
OK I managed to solve this issue. 好的,我设法解决了这个问题。 Apparently jstree does accept the 'undetermined'-state (when using the latest version of the library, in my case 3.0.2), as this answer already suggested, but it only works when the 'selected'-state is omitted (which makes sense). 显然,jstree 确实接受“不确定”状态(当使用最新版本的库时,在我的情况下为3.0.2),正如该答案已经建议的那样,但是它仅在省略“ selected”状态时才有效(这使得感)。 Refer to the issue I filed on Github for some more details. 有关更多详细信息,请参阅我在Github上提交的问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.