jQuery文件树-如何在文件夹单击时返回文件夹名称 [英] Jquery File Tree - how to return folder name on folder click

查看:88
本文介绍了jQuery文件树-如何在文件夹单击时返回文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have installed and trying to customize Jquery File Tree so that, on click of folder name, the folder name and path are returned to the calling function. Currently it only expands and collapses folders, and returns the file name on click of file.

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

So I need to return the folder too and cannot see where that is triggered.

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

I am using the php connector. Below link is where I downloaded the sample code: http://abeautifulsite.net/blog/2008/03/jquery-file-tree/

谢谢, 埃德

推荐答案

不确定是否存在"API"方法.但是,如果您查看源代码(第64-81行)

Not sure if there is an "API" way to do it. But if you look at the source code (Line 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子句中调用另一个函数,它将起作用.

Looks like you can call another function inside the hasClass('directory') if clause and it will work.

因此您可以:

将第36行更改为

fileTree: function(o, h, dire) {

在65至66之间添加

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

如果您想获得更多控制/灵活性/信息,可以执行dire($(this));,它将发送jQuery对象而不是仅发送rel属性.

If you want to have more control/flexibility/information, you can do dire($(this)); , and it will send the jQuery object instead of just the rel attribute.

示例:

$(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
    });
});

我尚未测试过,您可能需要更改几处内容.

I have not tested it, you might need to change a couple of things around.

这篇关于jQuery文件树-如何在文件夹单击时返回文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆