jq 目录树ajax,javascript
我正在尝试创建一种查看CSV文件的方法,该文件包含有关物理驱动器上的文件夹和子文件夹的详细信息。
这是CSV文件:
Volume,Path,Name,Size,Ext,Last modified,Description
"Music","/All Rock Music/All Rock Albums/Rock Album","01. Track 1.mp3",4274491,"mp3",2019-05-23 17:35:23,""
我已经使用papa parse plugin将此csv转换为javascript数组。 现在,我发现此插件可以创建用于查看文件的树形结构。 由于我不需要服务器,因此php无法运行。
在他们的github页面上,它说:
您可以创建自定义连接器脚本来扩展文件树的功能。 最简单的方法可能是修改下载中提供的脚本之一。 如果要从头开始,脚本应接受一个POST变量(dir),并以以下格式输出未排序的列表:
- Folder Name
(additional folders here)
filename.txt
(additional files here)
请您建议不使用PHP的情况下如何使用此插件?
此外,此文件树插件还有一个替代方案。请在此处查看
它要求我的html结构为:
- Root node 1
- Child node 1
- Child node 2
- Root node 2
我的file_data_array是: data[i][1]其中
data是目录/子目录中所有文件的数组。
i是迭代器。
1是此csv标头中的文件路径:
体积,
小路,
名称,
尺寸,
分机号
最后修改,
描述
知道如何使用上述数组使用jstree创建带有目录及其文件和子目录的文件树吗?
编辑:我发现此PHP脚本在服务器端生成UL列表。 有人可以建议如何在javascript中为客户端创建相同的列表吗? 我有一个csv文件输入,因此不需要ajax请求。
代码:
ini_set('open_basedir', dirname(__FILE__) . DIRECTORY_SEPARATOR);
class fs
{
protected $base = null;
protected function real($path) {
$temp = realpath($path);
if(!$temp) { throw new Exception('Path does not exist: ' . $path); }
if($this->base && strlen($this->base)) {
if(strpos($temp, $this->base) !== 0) { throw new Exception('Path is not inside base ('.$this->base.'): ' . $temp); }
}
return $temp;
}
protected function path($id) {
$id = str_replace('/', DIRECTORY_SEPARATOR, $id);
$id = trim($id, DIRECTORY_SEPARATOR);
$id = $this->real($this->base . DIRECTORY_SEPARATOR . $id);
return $id;
}
protected function id($path) {
$path = $this->real($path);
$path = substr($path, strlen($this->base));
$path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
$path = trim($path, '/');
return strlen($path) ? $path : '/';
}
public function __construct($base) {
$this->base = $this->real($base);
if(!$this->base) { throw new Exception('Base directory does not exist'); }
}
public function lst($id, $with_root = false) {
$dir = $this->path($id);
$lst = @scandir($dir);
if(!$lst) { throw new Exception('Could not list path: ' . $dir); }
$res = array();
foreach($lst as $item) {
if($item == '.' || $item == '..' || $item === null) { continue; }
$tmp = preg_match('([^ a-zа-я-_0-9.]+)ui', $item);
if($tmp === false || $tmp === 1) { continue; }
if(is_dir($dir . DIRECTORY_SEPARATOR . $item)) {
$res[] = array('text' => $item, 'children' => true, 'id' => $this->id($dir . DIRECTORY_SEPARATOR . $item), 'icon' => 'folder');
}
else {
$res[] = array('text' => $item, 'children' => false, 'id' => $this->id($dir . DIRECTORY_SEPARATOR . $item), 'type' => 'file', 'icon' => 'file file-'.substr($item, strrpos($item,'.') + 1));
}
}
if($with_root && $this->id($dir) === '/') {
$res = array(array('text' => basename($this->base), 'children' => $res, 'id' => '/', 'icon'=>'folder', 'state' => array('opened' => true, 'disabled' => true)));
}
return $res;
}
public function data($id) {
if(strpos($id, ":")) {
$id = array_map(array($this, 'id'), explode(':', $id));
return array('type'=>'multiple', 'content'=> 'Multiple selected: ' . implode(' ', $id));
}
$dir = $this->path($id);
if(is_dir($dir)) {
return array('type'=>'folder', 'content'=> $id);
}
if(is_file($dir)) {
$ext = strpos($dir, '.') !== FALSE ? substr($dir, strrpos($dir, '.') + 1) : '';
$dat = array('type' => $ext, 'content' => '');
switch($ext) {
case 'txt':
case 'text':
case 'md':
case 'js':
case 'json':
case 'css':
case 'html':
case 'htm':
case 'xml':
case 'c':
case 'cpp':
case 'h':
case 'sql':
case 'log':
case 'py':
case 'rb':
case 'htaccess':
case 'php':
$dat['content'] = file_get_contents($dir);
break;
case 'jpg':
case 'jpeg':
case 'gif':
case 'png':
case 'bmp':
$dat['content'] = 'data:'.finfo_file(finfo_open(FILEINFO_MIME_TYPE), $dir).';base64,'.base64_encode(file_get_contents($dir));
break;
default:
$dat['content'] = 'File not recognized: '.$this->id($dir);
break;
}
return $dat;
}
throw new Exception('Not a valid selection: ' . $dir);
}
public function create($id, $name, $mkdir = false) {
$dir = $this->path($id);
if(preg_match('([^ a-zа-я-_0-9.]+)ui', $name) || !strlen($name)) {
throw new Exception('Invalid name: ' . $name);
}
if($mkdir) {
mkdir($dir . DIRECTORY_SEPARATOR . $name);
}
else {
file_put_contents($dir . DIRECTORY_SEPARATOR . $name, '');
}
return array('id' => $this->id($dir . DIRECTORY_SEPARATOR . $name));
}
public function rename($id, $name) {
$dir = $this->path($id);
if($dir === $this->base) {
throw new Exception('Cannot rename root');
}
if(preg_match('([^ a-zа-я-_0-9.]+)ui', $name) || !strlen($name)) {
throw new Exception('Invalid name: ' . $name);
}
$new = explode(DIRECTORY_SEPARATOR, $dir);
array_pop($new);
array_push($new, $name);
$new = implode(DIRECTORY_SEPARATOR, $new);
if($dir !== $new) {
if(is_file($new) || is_dir($new)) { throw new Exception('Path already exists: ' . $new); }
rename($dir, $new);
}
return array('id' => $this->id($new));
}
public function remove($id) {
$dir = $this->path($id);
if($dir === $this->base) {
throw new Exception('Cannot remove root');
}
if(is_dir($dir)) {
foreach(array_diff(scandir($dir), array(".", "..")) as $f) {
$this->remove($this->id($dir . DIRECTORY_SEPARATOR . $f));
}
rmdir($dir);
}
if(is_file($dir)) {
unlink($dir);
}
return array('status' => 'OK');
}
public function move($id, $par) {
$dir = $this->path($id);
$par = $this->path($par);
$new = explode(DIRECTORY_SEPARATOR, $dir);
$new = array_pop($new);
$new = $par . DIRECTORY_SEPARATOR . $new;
rename($dir, $new);
return array('id' => $this->id($new));
}
public function copy($id, $par) {
$dir = $this->path($id);
$par = $this->path($par);
$new = explode(DIRECTORY_SEPARATOR, $dir);
$new = array_pop($new);
$new = $par . DIRECTORY_SEPARATOR . $new;
if(is_file($new) || is_dir($new)) { throw new Exception('Path already exists: ' . $new); }
if(is_dir($dir)) {
mkdir($new);
foreach(array_diff(scandir($dir), array(".", "..")) as $f) {
$this->copy($this->id($dir . DIRECTORY_SEPARATOR . $f), $this->id($new));
}
}
if(is_file($dir)) {
copy($dir, $new);
}
return array('id' => $this->id($new));
}
}
if(isset($_GET['operation'])) {
$fs = new fs(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'root' . DIRECTORY_SEPARATOR);
try {
$rslt = null;
switch($_GET['operation']) {
case 'get_node':
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$rslt = $fs->lst($node, (isset($_GET['id']) && $_GET['id'] === '#'));
break;
case "get_content":
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$rslt = $fs->data($node);
break;
case 'create_node':
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$rslt = $fs->create($node, isset($_GET['text']) ? $_GET['text'] : '', (!isset($_GET['type']) || $_GET['type'] !== 'file'));
break;
case 'rename_node':
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$rslt = $fs->rename($node, isset($_GET['text']) ? $_GET['text'] : '');
break;
case 'delete_node':
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$rslt = $fs->remove($node);
break;
case 'move_node':
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$parn = isset($_GET['parent']) && $_GET['parent'] !== '#' ? $_GET['parent'] : '/';
$rslt = $fs->move($node, $parn);
break;
case 'copy_node':
$node = isset($_GET['id']) && $_GET['id'] !== '#' ? $_GET['id'] : '/';
$parn = isset($_GET['parent']) && $_GET['parent'] !== '#' ? $_GET['parent'] : '/';
$rslt = $fs->copy($node, $parn);
break;
default:
throw new Exception('Unsupported operation: ' . $_GET['operation']);
break;
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($rslt);
}
catch (Exception $e) {
header($_SERVER["SERVER_PROTOCOL"] . ' 500 Server Error');
header('Status: 500 Server Error');
echo $e->getMessage();
}
die();
}
?>
jq 目录树ajax,javascript相关推荐
- 用Ajax做的一棵无限级目录树
转载:快乐笛子的博客(http://www.happyshow.org/view.php?id=107) 演示地址:http://www.happyshow.org/sample/20060918/a ...
- HTML ajax控件 目录树
/// <summary> /// 目录树 /// </summary> /// <param name="ca ...
- 伟景行citymaker-----01.javascript打开本地模型CEP,加载目录树,加载要素类
以下所有代码基于 CityMaker_IE_Plugin_vConnect8.0.171127.exe 版本 该版本只能使用IE打开,建议使用IE11 下载代码案例 1.打开cep模型代码 1.1 ...
- 实现ztree结合jquery的smartMenu.js插件对目录树的增删改查
问题:项目上遇到一个问题,需要作出一个目录树显示相关内容的层级结构关系. 插件: 目录树插件,在这里我选用了ztree,十分方便好用(UI有待提升哈~)下方是ztree插件 需要的自取 ztree插件 ...
- oracle 生成目录树,jQuery zTree插件快速实现目录树
ztree是JQuery的一个开源树形目录的插件,用来快速构建网站的树形目录结构,并且提供了功能丰富,利于扩展的API. JQuery ztree官网 只要引入jquery和ztree的库js,然后给 ...
- Windows命令行tree命令打印目录树
tree $DIRNAME打印目录$DIRNAME下的目录树(只打印目录名,不打印文件名).不加$DIRNAME打印当前路径的目录树.例如在D:\da_kao_la\workspace\Charact ...
- 生成百度网盘可折叠目录树教程 百度网盘html可折叠目录树
最后有全部代码,可直接复制拿走运行 先看最终效果 白色字体为文件夹 黑色字体为文件 可以点击实现展开和折叠 生成网页html形式的百度网盘可折叠目录树教程-超详细 前言 正文 需要的软件及环境 使用教 ...
- 看很多人要求目录树,我的代码可以满足大多数要求 作 者: flyxxxxx (灭神)
<script language="javascript" type="text/javascript"> document.title=" ...
- jquery php实现目录树,Html5文件目录树结构
外的其他页面文件:css放所有的css文件,包括字体文件,less文件,scss文件:img放所有的图片文件,svgGy1网址提交_网站收录_网站分类目录_中文网站排行-好五七八目录 由于工作中业务需 ...
- Dtree目录树的总结
把dtree.css 和dtree.js及img文件夹放到页面的根文件夹下就可以用! Dtree目录树的总结 一:函数 1:页面中 tree.add(id,pid,name,url,title,tar ...
最新文章
- Vue.js 是什么
- 图像分析:投影曲线的波峰查找
- 【Android FFMPEG 开发】Android Studio 中 配置 FFMPEG 库最小兼容版本 ( undefined reference to 'atof' )
- 获取MSSQL Server中的相关信息(视图、存储过程、触发器、表)
- 中文转unicode,中文转bytes,unicode转bytes java实现
- 爆发前的最后按钮 白鹭推HTML5首款生态产品Egret Runtime
- node.js应用生成windows server的plugin——winser
- 属性子集选择的基本启发方法_Java机器学习库(Java ML)(三、特征选择)
- 华为机试HJ42:学英语
- Bailian2756 二叉树(POJ NOI0306-1758)【二叉树】
- 在线编辑fckeditor3
- 计算机导论知识体系,《计算机导论》课程知识体系结构研究
- 微信开发者工具小技巧——快速打开微信程序API文档。
- IconFont使用方式简介
- springboot记录用户访问次数_Spring Boot入门(12)实现页面访问量统计功能
- HP暗影精灵7笔记本OMEN16.1inch Gaming Laptop PC16-b0000原装出厂Win11系统恢复原厂OEM系统
- 基于Atmel128A单片机的MP31.0设计
- 微信自定义分享、二次分享解决方案
- 射击末世--代理模式
- springboot整合bboss操作elasticsearch
热门文章
- oracle对星期排序,oracle rownum对排序的影响
- 制作数据集---labelImg和labelme
- oracle 高速保存数据,教你怎样在Oracle数据库中高速导出/导入(一)
- java 接受gsm信息_android 获取手机GSM/CDMA信号信息,并获得基站信息
- java构建模式_《Java设计模式》之构建者模式
- react手机机端css_create-react-app创建react项目 css模块化处理
- mysql load data infile 上传数据 不显示_第22问:我有带外键的表,你有数据么?
- composer 介绍及安装
- php 处理vue上传图片 base64_encode file_put_contents file_get_contents
- mssql sqlserver 验证整型函数分享