我有目录数组
[{"10000":[]},{"10006":[]},{"10011":[]},{"TEST1":[{"10011":[]},{"11111_old":[]}]},{"TEST2":[{"10000":[]},{"10001":[{"10000":[]}]},{"10007":[{"10006":[]}]}]},{"TEST3":[{"10006":[]},{"10012":[{"10011":[]}]}]}]
当json_decode $dir_array = json_decode($treedata,true);
时,我在网页中的树状视图数据中显示this
所以,当我点击第一级10000时,我得到密钥10000作为文本,即第一个键,但是当我点击第二级10007时,我得到它的键作为文本相同10007,我想得到像" TEST2 / 10007& #34;而不仅仅是文字" 10007"。
当我点击10011时,第三级层次结构相同,我只获得10011键作为文本而不是" TEST3 / 10012/10011"
当我点击特定的"10000", "TEST2/10007", "TEST3/10012/10011"
时,我能否获得上述文本数据。
单击数组中的Last元素时,只想将TOP到LAST Structure作为TEXT。
更新了代码
</!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function downloadspecificcompany(cmp)
{
console.log(cmp);
if(cmp.toString().indexOf("http") != -1){
console.log("Some folder found not company -->"+cmp);
var arr = cmp.toString().split('/');
console.log(arr);
var cmp = arr[3];
console.log("ompany found-->"+cmp);
}
else
{
console.log("company found-->"+cmp);
}
}
</script>
<!-- Treeview starts -->
<script src="js/file-explore.js"></script>
<link href="http://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css">
<link href="css/file-explore.css" rel="stylesheet" type="text/css">
<style>
body{font-family:'Roboto',Arial, Helvetica, sans-serif; background-color:#fafafa;}
.container { margin:150px auto; max-width:728px;}
</style>
<!-- $(".file-tree").filetree(); -->
<!-- Treeview ends -->
</head>
<body>
<?php
$dir = "/usr/share/Data/rahul/";
/*
This is directory folder
├── 10000
├── 10000_Backup
│ └── 10000
├── 10006
├── 10011
├── 10011_Backup
│ └── 10011
├── TEST1
│ ├── 10011
│ └── 11111_old
├── TEST2
│ ├── 10000
│ ├── 10001
│ │ └── 10000
│ └── 10007
│ └── 10006
└── TEST3
├── 10006
└── 10012
└── 10011
*/
$a1 = listFolders($dir);
$treedata = json_encode($a1);
function listFolders($dir)
{
$dh = preg_grep("/(\w+)_Backup/", scandir($dir), PREG_GREP_INVERT);
$return = array();
foreach ($dh as $folder)
{
if ($folder != '.' && $folder != '..')
{
if (is_dir($dir . '/' . $folder))
{
$return[] = array($folder => listFolders($dir . '/' . $folder));
}
}
}
return $return;
}
$dir_array = json_decode($treedata,true);
function mygenerateTreeMenu($dir_array,$limit = 0)
{
$key = '';
$tree = '';
if ($limit > 1000) return '';
foreach ($dir_array as $key => $value)
{
if (!is_int($key))
{
$tree .= "<li class='treeclass'>";
$tree .= "<a href='#' onclick='downloadspecificcompany($key);' id='".$key."'>$key</a><ul>";
$tree .= mygenerateTreeMenu($value,$limit++);
$tree .= "</ul></li>\n";
}
else
{
if($key>100){
$tree .= "<li class='treeclass'>";
$tree .= "<a href='#' onclick='downloadspecificcompany($key);' id='".$key."'>$key</a><ul>";
$tree .= mygenerateTreeMenu($value,$limit++);
$tree .= "</ul></li>\n";
}
else{
$tree .= mygenerateTreeMenu($value,$limit++);
}
}
}
return $tree;
}
echo "<ul class='file-tree' style='padding-left: 0px;'>\n";
$finaltree = mygenerateTreeMenu($dir_array);
echo $finaltree;
echo "</ul>\n";
?>
</body>
</html>