我需要避免单击 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/