dql123000 2017-12-22 01:50
浏览 48

Treeview Directory对Datatable做出反应

I have a treeview directory. The directory is an actual viewing of folders with files on it and beside the treeview of directory I have a datatable. The interface looks like this:

Treeview

When I click a treeview it will show its path through alert. Like this:( I clicked the runblack.png).

enter image description here

My question is how can I make the treeview react with the datatable beside. Like if I click the year the datatable will search all files with the same year. Then if i click the category below the year it will search the category with the year.

This is my code for the directory:

<?php

function php_file_tree($directory, $return_link, $extensions = array()) {
    // Generates a valid XHTML list of all directories, sub-directories, and files in $directory
    // Remove trailing slash
    if( substr($directory, -1) == "/" ) $directory = substr($directory, 0, strlen($directory) - 1);
    $code .= php_file_tree_dir($directory, $return_link, $extensions);
    return $code;
}

function php_file_tree_dir($directory, $return_link, $extensions = array(), $first_call = true) {
    // Recursive function called by php_file_tree() to list directories/files
    
    // Get and sort directories/files
    if( function_exists("scandir") ) $file = scandir($directory); else $file = php4_scandir($directory);
    natcasesort($file);
    // Make directories first
    $files = $dirs = array();
    
    
    foreach($file as $this_file) {
        if( is_dir("$directory/$this_file" ) ) $dirs[] = $this_file; else $files[] = $this_file;
    }
    $file = array_merge($dirs, $files);
    
    // Filter unwanted extensions
    if( !empty($extensions) ) {
        foreach( array_keys($file) as $key ) {
            if( !is_dir("$directory/$file[$key]") ) {
                $ext = substr($file[$key], strrpos($file[$key], ".") + 1); 
                if( !in_array($ext, $extensions) ) unset($file[$key]);
            }
        }
    }
    
    if( count($file) > 2 ) { // Use 2 instead of 0 to account for . and .. "directories"
        $php_file_tree = "<ul";
        if( $first_call ) { $php_file_tree .= " class=\"dirlist\""; $first_call = false; }
        $php_file_tree .= ">";
        foreach( $file as $this_file ) {
            if( $this_file != "." && $this_file != ".." ) {
                if( is_dir("$directory/$this_file") ) {
                    // Directory
                    $flink="./$directory/$this_file";
                    $dlink = str_replace("[link]", "$directory/". urlencode($this_file), $return_link);
                    $php_file_tree .= "<li class=\"hdir\" ><a href=\"$dlink\">" . htmlspecialchars($this_file)."</a>" ;
                    
                    $php_file_tree .= php_file_tree_dir("$directory/$this_file", $return_link ,$extensions, false);
                    
                    $php_file_tree .= "</li>";
                } else {
                    // File
                    // Get extension (prepend 'ext-' to prevent invalid classes from extensions that begin with numbers)
                    $ext = "ext-" . substr($this_file, strrpos($this_file, ".") + 1); 
                    $link = str_replace("[link]", "$directory/" . urlencode($this_file), $return_link);
                    $flink="./$directory/" . urlencode($this_file);
                    $fsize = filesize ("$flink");
                    
                    $ftime=date ("F d Y H:i:s.", filemtime($flink));
                    $php_file_tree .= "<li class=\"hfile " . strtolower($ext) . "\"><a href=\"$link\">" . htmlspecialchars($this_file) . "</a><br></li>";
                }
            }
        }
        $php_file_tree .= "</ul>";
    }
    return $php_file_tree;
}

// For PHP4 compatibility
function php4_scandir($dir) {
    $dh  = opendir($dir);
    while( false !== ($filename = readdir($dh)) ) {
        $files[] = $filename;
    }
    sort($files);
    return($files);
}

I want it like when the treeview is clicked I will pass a query to the datatable to search for the needed data.

Query example: SELECT * FROM TABLE WHERE DATE = 'from treeview' AND CATEGORY = 'from treeview' ... and so on

My datatable viewing of data from the database is just the usual javascript to php connection for select.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算