duanguanye4124 2012-04-16 16:30
浏览 39
已采纳

文件夹选择对话的性能

I need to present a folder selection of the entire hard drive of the user (script runs on the user pc). From that list the user can choose one or more folders. I am using the jquery library dynatree (http://code.google.com/p/dynatree/) for presentation.

My script works like this:

1.List all folders of a specified drive letter or path and parse it into Dynatree-readable format via this recursive function:

Code:

function getDirectory( $path = '.', $level = 0, $id = 0){ 
$ignore = array( 'cgi-bin', '.', '..' , 'windows', 'user_folders', 'user_profiles'); 
$dh = @opendir( $path ); 
$zaehl = 0; 
if($level != 0) echo(', children: [ ');
while( false !== ( $file = readdir( $dh ))){ 
$zaehl++;
      if( !in_array( strtolower($file), $ignore ) ){ 
        $spaces = str_repeat( ' ', ( $level * 4 ) ); 
        if( is_dir( "$path/$file" ) ){
        echo('{title: "'.$file.'", isFolder: true, key: "'.$path.'/'.$file.'"');
    echo("
"); 
            getDirectory( "$path/$file", ($level+1), $id.'.'.$zaehl); 
    echo('},');
    echo("
");

        }       

    } 

} 
 if($level != 0)
    {
        echo(']');
    }
closedir( $dh ); 
} 

2.Present the list using Dynatree:

        $("#tree3").dynatree({

        checkbox: true,

        selectMode: 3,

        children: treeData,

        onSelect: function(select, node) {

            var selKeys = $.map(node.tree.getSelectedNodes(), function(node){

                return node.data.key;

            });
            var selRootNodes = node.tree.getSelectedNodes(true);
            var selRootKeys = $.map(selRootNodes, function(node){
                return node.data.key;
            });
            $("#echoSelectionRootKeys3").text(selRootKeys.join(", "));
            $("#echoSelectionRoots3").text(selRootNodes.join(", "));
        },
        onDblClick: function(node, event) {
            node.toggleSelect();
        },
        onKeydown: function(node, event) {
            if( event.which == 32 ) {
                node.toggleSelect();
                return false;
            }
        }
    });

I don´t think that process number 2 is the problem, as i basically copied it from the creators tutorial. I think that I´ve made a mistake during process 1 while listing the folders.

Running the getDirectory script with a parameter of a harddrive with few folders it works like a charm. When it comes to (typically) harddrives with lots of nested folders it lasts there several minutes.

Does anybody know a better way of listing the folders or a complete different solution for presenting a server-side folder creation dialogue?

  • 写回答

2条回答 默认 最新

  • dpwjx32578146 2012-04-18 12:44
    关注

    If you are complaining about speed, I would suggest Lazy Loading. If you are loading every folder/file in your directory, it will become very slow.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了