【发布时间】:2016-08-09 02:27:56
【问题描述】:
我正在使用库 phpseclib。为了显示目录列表,我使用函数:
$sftp->rawlist();
但它不会将树列表显示为其示例的图像 (http://phpseclib.sourceforge.net/sftp/examples.html)
如何才能将其显示为下图?谢谢。
【问题讨论】:
我正在使用库 phpseclib。为了显示目录列表,我使用函数:
$sftp->rawlist();
但它不会将树列表显示为其示例的图像 (http://phpseclib.sourceforge.net/sftp/examples.html)
如何才能将其显示为下图?谢谢。
【问题讨论】:
phpseclib 的文档在 git 中:
https://github.com/phpseclib/docs
看...文档网站使用http://bassistance.de/jquery-plugins/jquery-plugin-treeview/ 来实现您所询问的效果。要将 PHP 数组转换为适用于该插件的 HTML...
function array2html($array)
{
$result = '';
foreach ($array as $key => $value) {
$result.= '<li><span class="name">' . $key . '</span>' . (is_array($value) ? array2html($value) : '<ul><li>' . $value . '</li></ul>') . '</li>';
}
return '<ul>' . $result . '</ul>';
}
所以在 PHP 中你会想要这样做(一旦上面的函数被定义):
echo str_replace('<ul>', '<ul class="printr">', array2html($arr), 1);
在 HTML 中你需要这样做:
$(document).ready(function() {
$('.printr').treeview({ persist: "location", collapsed: true, unique: true });
}
请记住,看起来 phpseclib 文档确实对树视图库进行了至少一项更改(修改了一些 CSS 并添加了新图像):
https://github.com/phpseclib/docs/commit/3406a94489c153ddf8f4a1a33f2ecbbcdd5ec61e
希望有帮助!
【讨论】: