0

クライアントJavaScriptですべてのノードを展開および折りたたむために、このアプローチに従っています:http ://www.telerik.com/help/aspnet/treeview/tree_expand_client_side.html

ただし、これを処理するには非常に長い時間がかかり、展開してから折りたたむと「スクリプトが応答しません」というエラーが発生するので、かなり大きなツリーでこれを高速化する方法があるかどうか疑問に思いました。それを解析するためのより良い方法はありますか?現在、ツリーの深さは4レベルです。

ありがとう。

4

2 に答える 2

1

からノードを取得し、次に子ノードをyourtreeViewInstance.get_nodes()階層eachChildNode.get_nodes()の下位に配置します。

.set_expanded(true);次に、展開する各ノードを呼び出すことにより、各アイテムを展開できます。

于 2011-11-15T06:43:55.310 に答える
1

ツリーを非同期的に展開および折りたたむことで、「スクリプトが応答しません」というエラーを回避しました。さらに、下から展開し (ノードが展開されているのがわかります)、上から折りたたむようにしていますが、それは各ブランチの最後のノードに到達したときのみなので、視覚的にはユーザーにとってはるかに興味深いものです。彼らは実際にそれが起こるのを見ることができ、それが速くない場合 (IE7 以前は特に遅い)、少なくとも彼らが待っている間は楽しいものです。

var treeView, nodes;

function expandAllNodesAsynchronously() {
    if (<%= expandedLoaded.ToString().ToLower() %>) {
        treeView = $find("<%= tv.ClientID %>");
        nodes = treeView.get_allNodes();
        if (nodes.length > 1) {
            doTheWork(expandOneNode, nodes.length);
        }
        return false;
    } else
        return true;
}

function expandOneNode(whichNode) {
    var actualNode = nodes.length - whichNode;
    if (nodes[actualNode].get_nextNode() == null) {
        nodes[actualNode].get_parent().expand();
    }
}

function collapseAllNodesAsynchronously() {
    treeView = $find("<%= tv.ClientID %>");
    nodes = treeView.get_allNodes();
    if (nodes.length > 1) {
        doTheWork(collapseOneNode, nodes.length);
    }
}

function collapseOneNode(whichNode) {
    if (nodes[whichNode].get_nextNode() == null && nodes[whichNode].get_parent() != nodes[0]) {
        nodes[whichNode].get_parent().collapse();
    }
}

function doTheWork(operation, cycles) { //, callback
    var self = this, // in case you need it
        cyclesComplete = 1,
        batchSize = 10; // Larger batch sizes will be slightly quicker, but visually choppier

    var doOneBatch = function() {
        var c = 0;
        while(cyclesComplete < cycles) {
            operation(cyclesComplete);
            c++;
            if(c >= batchSize) {
                // may need to store interim results here
                break;
            }
            cyclesComplete++;
        }
        if (cyclesComplete < cycles) {
            setTimeout(doOneBatch, 1); // "1" is the length of the delay in milliseconds
        }
        else {
            // Not necessary to do anything when done
            //callback(); // maybe pass results here
        }
    };

    // kickoff
    doOneBatch();
    return null;
};
于 2013-08-19T19:02:04.150 に答える