让jQueryFileTree 支持自定义树和中文
jQueryFileTree插件的使用方法点这里
jQueryFileTree只支持列表出文件,且对中文不支持
1.如何才能让其支持自定义的列表呢?
将以下代码以UTF-8码保存为custom.php
<?php
header("Content-Type:text/html;charset=utf-8");
$dir = trim($_POST['dir'],"/");
//树结构
$data=array(
"文件夹1"=>array(
"file1"=>"item1",
"file2"=>"item2",
"folder11"=>array(
"file6"=>"item6"
)
),
"folder2"=>array(
"file3"=>"item3",
"file4"=>"item4"
),
"项目"=>"item5"
);
//处理过程
$n_data=$data;
$n_dir=explode("/",$dir);
if($dir!==""){
foreach($n_dir as $v){
$n_data=$n_data[$v];
}
}
echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
foreach($n_data as $key=>$value){
if(is_array($value))
echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . $dir ."/". $key ."/". "\">" . $key . "</a></li>";
else
echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . $value . "\">" . $key . "</a></li>";
}
echo "</ul>";
?>
header("Content-Type:text/html;charset=utf-8");
$dir = trim($_POST['dir'],"/");
//树结构
$data=array(
"文件夹1"=>array(
"file1"=>"item1",
"file2"=>"item2",
"folder11"=>array(
"file6"=>"item6"
)
),
"folder2"=>array(
"file3"=>"item3",
"file4"=>"item4"
),
"项目"=>"item5"
);
//处理过程
$n_data=$data;
$n_dir=explode("/",$dir);
if($dir!==""){
foreach($n_dir as $v){
$n_data=$n_data[$v];
}
}
echo "<ul class=\"jqueryFileTree\" style=\"display: none;\">";
foreach($n_data as $key=>$value){
if(is_array($value))
echo "<li class=\"directory collapsed\"><a href=\"#\" rel=\"" . $dir ."/". $key ."/". "\">" . $key . "</a></li>";
else
echo "<li class=\"file ext_$ext\"><a href=\"#\" rel=\"" . $value . "\">" . $key . "</a></li>";
}
echo "</ul>";
?>
在调用页的调用
$('#container_id2').fileTree({
root: '/',
script: 'custom.php',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: false
}, function(file) {
alert(file);
});
root: '/',
script: 'custom.php',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: false
}, function(file) {
alert(file);
});
2.使其支持中文文件 - 修改了jQueryFileTree.js,jQueryFileTree.php文件
调用
$('#container_id').fileTree({
root: './',
script: 'jqueryfiletree.php',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: false
}, function(file) {
alert(file);
});
root: './',
script: 'jqueryfiletree.php',
expandSpeed: 1000,
collapseSpeed: 1000,
multiFolder: false
}, function(file) {
alert(file);
});