【问题标题】:Jquery File Tree - how to return folder name on folder clickJquery 文件树 - 如何在文件夹单击时返回文件夹名称
【发布时间】:2010-10-22 21:09:28
【问题描述】:

我已经安装并尝试自定义 Jquery 文件树,以便在单击文件夹名称时,将文件夹名称和路径返回给调用函数。目前它只展开和折叠文件夹,并在单击文件时返回文件名。

所以我也需要返回文件夹并且看不到触发的位置。

我正在使用 php 连接器。 下面的链接是我下载示例代码的地方: http://abeautifulsite.net/blog/2008/03/jquery-file-tree/

谢谢, 埃德

【问题讨论】:

  • 添加你的连接器脚本和你当前的 jQuery,我会告诉你需要什么。

标签: javascript jquery file treeview tree


【解决方案1】:

不确定是否有“API”方法可以做到这一点。但是如果你看一下源代码(第 64-81 行)

if( $(this).parent().hasClass('directory') ) {
    if( $(this).parent().hasClass('collapsed') ) {
        // Expand
        if( !o.multiFolder ) {
            $(this).parent().parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
            $(this).parent().parent().find('LI.directory').removeClass('expanded').addClass('collapsed');
        }
        $(this).parent().find('UL').remove(); // cleanup
        showTree( $(this).parent(), escape($(this).attr('rel').match( /.*\// )) );
        $(this).parent().removeClass('collapsed').addClass('expanded');
    } else {
        // Collapse
        $(this).parent().find('UL').slideUp({ duration: o.collapseSpeed, easing: o.collapseEasing });
        $(this).parent().removeClass('expanded').addClass('collapsed');
    }
} else {
    h($(this).attr('rel'));
}

看起来你可以在hasClass('directory') if 子句中调用另一个函数,它会起作用。

所以你可以:

将第 36 行更改为

fileTree: function(o, h, dire) {

65到66之间加

dire($(this).attr('rel'));

如果你想拥有更多的控制/灵活性/信息,你可以做dire($(this));,它会发送jQuery对象而不是rel属性。

示例:

$(document).ready( function() {
    $('#container_id').fileTree({ root: '/some/folder/' }, function(file) {
        // do something when a file is clicked
    }, function(dir){
        // do something when a dir is clicked
    });
});

我没有测试过,你可能需要改变一些东西。

【讨论】:

    【解决方案2】:

    效果很好,我只是将最后一个函数更改为“可怕”,就像它是第 65 行和第 66 行之间的代码一样

            ... function(dire){
    // do something when a dir is clicked
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2012-10-26
      • 2013-12-17
      • 1970-01-01
      • 2020-05-03
      相关资源
      最近更新 更多