2

I am using the jQuery Treeview plugin. Have a look to the "Sample 1 - default" provided on the demo page of the plugin http://jquery.bassistance.de/treeview/demo/. In my case all folders and files are links. If I click for example on the expanded "Folder 2" it will first collapse and then follow to the link location. The behaviour I would like to is, that only collapsed ones will expand first and if it already expanded it will stay like this.

The code in the plugin (jquery.treeview.js) which toggle the behaviour is the following:

66 this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
67 toggler.apply($(this).next());
68 }).add( $("a", this) ).hoverClass(); 

I already figured out how to get all the links, which should be changed:

$('a').parent().parent().filter('.collapsable')

The result will be a array of all li which are currently collapsable (expanded): [li., li.collapsable]

But I don't know how to proceed from there :-( Hopefully someone could help me along...

I already changed sucessfully the linkbehavior for the current selected (class=selected) link with this code:

    $(".current").click(function(e){
        e.preventDefault();
    });

Many thanks in advance!

4

1 回答 1

2

也许不清楚我真正想做什么,所以下次我会努力提高我的语言表达能力;-)

我自己的问题的答案是:

$('li').filter('.collapsable').find('a:first:not(.current)').click(function(e){
            e.stopImmediatePropagation();
        });

也许它可以帮助正在寻找类似东西的人。

此致!!

更新(如果用户在未重新加载页面的情况下扩展节点,则上面发布的解决方案不起作用)

    $('a').click(function(e){
        if ($(this).is('.current')) {
            e.preventDefault();
        } else if ($(this).parent().parent().is('.collapsable')) {
            e.stopImmediatePropagation();
        };          
    });

这个按预期工作。:-)

于 2010-01-28T07:34:43.827 回答