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

查看:29
本文介绍了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 之间添加

Between 65 and 66 add

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天全站免登陆