jquery - 避免在 jquery 中单击 TreeView 文本时 TreeView 折叠

标签 jquery treeview

我需要避免单击 TreeView 链接/文本时 jquery TreeView 崩溃。

例如,如果我在 TreeView 中显示目录/子目录列表,则仅在单击+/-图像时才需要折叠 TreeView ,而不是在单击目录

最佳答案

您需要更新 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();

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

更好的是,您在定义树时提供一个新参数,并且仅当满足条件时才覆盖默认功能。例如,

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

您的 TreeView 定义可能如下所示:

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

希望你明白这个想法。祝你好运。

关于jquery - 避免在 jquery 中单击 TreeView 文本时 TreeView 折叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2006283/

相关文章:

jquery - 在页面模板中使用自定义 jquery

javascript - 高 map 中的动态悬停颜色

jquery - 是什么导致我的 nivo-slider 抛出以下错误?

javascript - 如何缩放 jsPlumb 图

绑定(bind)到 ObservableCollection 的 WPF TreeView 不更新根节点

python - 如何在 Treeview 中编辑标题的样式(Python ttk)

jQuery:如何创建元素然后将其包装在另一个现有元素周围?

vba - 缺少 Microsoft 通用控件

c# - 基于列以编程方式在共享点中创建 TreeView

c# - c#windows窗体中如何选择TreeView中的子节点