我正在使用 dynatree 插件来显示复选框树,使用多选模式(模式 3)。
当使用 ajax 初始化树时(没有延迟加载),似乎忘记了最初选择加载某些节点。当我选择其中一个节点时,传递给 onSelect 处理程序的标志值是 true,即:它认为我想选择节点。
当我再次单击复选框时,它会取消选择。在我实际单击复选框之前,似乎在后台没有注册选择。我想加载已选择此节点的树。
我用来加载树的 json 对我来说看起来不错;对于有问题的节点,即根节点,select属性为 true。这是 JSON 的一个片段:
{
"expand":true,
"title":"All",
"isFolder":false,
"key":"0",
"isLazy":false,
"addClass":null,
"select":true,
"unselectable":false,
"children": [... omitted for clarity]
}
更新
我以这种方式加载树:
$("#locationsTree").dynatree({
checkbox: true,
selectMode: 3,
initAjax: {
type: "POST",
url: dynaTreeInitUrl
},
classNames:
{
nodeIcon: ""
}
});
其中 dynaTreeInitUrl 是返回 json 的 url。
如果我像这样对 JSON 进行硬编码:
$("#locationsTree").dynatree({
checkbox: true,
selectMode: 3,
children: {
"expand":true,
"title":"All",
"isFolder":false,
"key":"0",
"isLazy":false,
"addClass":null,
"select":true,
"unselectable":false,
"children": [{
"expand": true,
"title": "Child",
"isFolder": false,
"key": "1",
"isLazy": false,
"addClass": null,
"select": true,
"unselectable": true,
"children": []
}]
},
classNames:
{
nodeIcon: ""
}
});
有用。:/
更新:
我发现了为什么会这样:
这是 dynatree 中的一个错误 - 或者可能是它试图过于聪明的预期行为。
如果子节点有unselectable = true,则即使父节点有select = true,加载子节点时也会取消选择父节点。这使得不可能创建一个选择是分层的树 - 即:拥有它以便如果选择了父项,则所有子项都会自动选择,并且不能取消选择。我想这可以作为另一种“模式”添加到 dynatree 中。