1

我正在使用 NODE 选项 expand = false 创建一个动态树。但是当我查看树时,它会在开始时显示所有已花费的内容。如何在初始阶段获得所有崩溃的树。下面是我的代码

$(function(){
            // Attach the dynatree widget to an existing <div id="tree"> element
            // and pass the tree options as an argument to the dynatree() function:
            $("#tree").dynatree({
                onActivate: function(node) {
                    // A DynaTreeNode object is passed to the activation handler
                    // Note: we also get this event, if persistence is on, and the page is reloaded.
                    //alert("You activated " + node.data.key);
                },
                persist: false,
                checkbox: true,
                generateIds: false,

                classNames: {
                    checkbox: "dynatree-checkbox",
                    expanded: "dynatree-expanded"
                },
                selectMode: 3,
                children: {!JsonString},
                onSelect: function(select, node) {
                    // Get a list of all selected nodes, and convert to a key array:
                    var selKeys = $.map(node.tree.getSelectedNodes(), function(node){
                        return node.data.key;
                    });
                    jQuery(document.getElementById("{!$Component.selectedKeys}")).val(selKeys.join(", "));

                    // Get a list of all selected TOP nodes
                    var selRootNodes = node.tree.getSelectedNodes(true);
                    // ... and convert to a key array:
                    var selRootKeys = $.map(selRootNodes, function(node){
                        return node.data.key;
                    });
                },

            });

        });
4

1 回答 1

1

在我的 dynatree 中,我在 init 上使用 AJAX 并展开整个树,但也许对我的代码的这种修改会对您有所帮助:

onPostInit: function(isReloading, isError) {
    this.$tree.dynatree('getRoot').visit(function(node){
        node.expand(false);
    });
}
于 2013-02-28T08:17:12.403 回答