单击动态树的节点时如何自动选择所有兄弟节点?我尝试了一些代码,但它不起作用。
问问题
1064 次
2 回答
0
您需要获取所选节点的父节点,然后是该父节点的子节点(因此是所选节点的兄弟节点)。
试试这个代码:
<script type="text/javascript">
$(function() {
$("#tree").dynatree({
onActivate: function(node) {
// Get the selected nodes parents children (the selected nodes siblings)
var siblings = node.getParent().getChildren();
// Loop through all the siblings and set selected to true
for(var i=0; i<siblings.length; i++)
{
siblings[i].select(true);
}
},
children: [
{title: "Folder", isFolder: true, key: "folder",
children: [ {title: "Sub-item 1"}, {title: "Sub-item 2"}, {title: "Sub-item 3"} ]
}
]
});
});
</script>
<div id="tree"></div>
于 2015-04-22T01:29:10.340 回答
0
很抱歉回复晚了..但这对遇到相同要求的其他人肯定会有所帮助。
我们需要做的就是将以下配置属性设置为 3。 selectMode:3 // 这是多层次的
它会根据子节点的状态自动处理更改父节点的状态,反之亦然。
谢谢, 奇特拉
于 2016-08-04T14:12:45.300 回答