点击jquery中的treeview文本,避免树视图崩溃

Pra*_*sad 4 treeview jquery

我需要在点击treeview链接/文本时避免jquery treeview的崩溃.

例如,如果我directories/subdirectories在树视图中显示一个列表,我只需要在单击时折叠树视图而+/- image不是单击directories

Ben*_*old 10

您需要更新treeview javascript代码本身.对于Treeview 1.4,请注释掉以下行(66-68):

this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
    toggler.apply($(this).next());
}).add( $("a", this) ).hoverClass();
Run Code Online (Sandbox Code Playgroud)

这将确保仅在+/-点击时发生展开/折叠.如果适用,展开全部和折叠所有功能也将继续有效.

更好的是,在定义树时提供新参数,并且只有满足条件才会覆盖默认功能.例如,

if (settings.expandMode != 'simple'){
    this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
        toggler.apply($(this).next());
    }).add( $("a", this) ).hoverClass();
}
Run Code Online (Sandbox Code Playgroud)

您的树视图定义可能如下所示:

$("#tree").treeview({
    animated: "fast",
    persist: "cookie",
    collapsed: true,
    control: "#treecontrol",
    expandMode: "simple" // custom - only toggles per the +/- icon      
})
Run Code Online (Sandbox Code Playgroud)

希望你明白了.祝好运.