我正在将 1000 多个节点(包括子节点)加载到一个动态树中,并为每个节点使用一个复选框来选择。
但是,如果我们像演示中那样全选或取消全选,http://wwwendt.de/tech/dynatree/doc/sample-select.html,它会非常慢并且浏览器会挂起 10 秒。
有解决办法吗?
编辑:一棵树有 6-8 层嵌套。每个级别大约有 5-10 个节点。
更新代码
<a href="#" id="select-all">select all</a>
<div id="echoSelection"></div>
<div id="my-tree"></div>
$('#select-all').click(function(){
alert($("#my-tree").dynatree("getRoot").length);
$("#my-tree").dynatree("getRoot").visit(function(node){
node.select(false);
});
return false;
});
$("#my-tree").dynatree({
initAjax: {
url: 'jsonData.aspx',
data: { type: "all" }
},
checkbox: true,
selectMode: 3,
onSelect: function (select, node) {
// Display list of selected nodes
var selNodes = node.tree.getSelectedNodes();
// convert to title/key array
var selKeys = $.map(selNodes, function (node) {
return "[" + node.data.key + "]: '" + node.data.title + "'";
});
$("#echoSelection2").text(selKeys.join(", "));
},
onClick: function (node, event) {
// We should not toggle, if target was "checkbox", because this
// would result in double-toggle (i.e. no toggle)
if (node.getEventTargetType(event) == "title")
node.toggleSelect();
},
onKeydown: function (node, event) {
if (event.which == 32) {
node.toggleSelect();
return false;
}
},
fx: { height: "toggle", duration: 200 },
autoCollapse: true
});
}
JSON 格式示例
[
{"title":"Node 1","isFolder":false,"isLazy":false,"key":"1","icon":null,"prevNode":0,"nextNode":0,"children":[{"title":"Node 6","isFolder":false,"isLazy":false,"key":"6","icon":null,"prevNode":0,"nextNode":0,"children":[],"tooltip":null,"addClass":null,"expand":false,"MetaData":null}],"tooltip":null,"expand":false,"MetaData":null},{"title":"Node 2","isFolder":false,"isLazy":false,"key":"2","icon":null,"prevNode":0,"nextNode":0,"children":[],"tooltip":null,"expand":false,"MetaData":null},{"title":"Node 3","isFolder":false,"isLazy":false,"key":"3","icon":null,"prevNode":0,"nextNode":0,"children":[],"tooltip":null,"expand":false,"MetaData":null}]