不确定是否有“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
});
});
我没有测试过,你可能需要改变一些东西。