避免treeview崩溃点击treeview链接/文本时,我需要避免jquery treeview的崩溃。jquery
例如,如果我显示的树状directories/subdirectories
名单,我要崩溃了树状只有同时点击+/- image
,而不是点击directories
避免treeview崩溃点击treeview链接/文本时,我需要避免jquery treeview的崩溃。jquery
例如,如果我显示的树状directories/subdirectories
名单,我要崩溃了树状只有同时点击+/- image
,而不是点击directories
你需要更新树形视图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
})
希望你明白我的意思。祝你好运。
绑定点击事件到+/-图像,而然后是包含图像和目录文本的容器。
所以,如果你的HTML看起来像这样:
<ul class="dir-list">
<li>
<div><img class="expand" src="expand.gif" /><span>Directory Name</span></div>
<ul>
<li><div><img class="expand" src="expand.gif" /><span>Sub Directory Name</span></div></li>
</ul>
</li>
</ul>
你会做你的点击图片绑定:
$('.dir-list img.expand').click(function(){
//Do stuff here to expand or collapse the area
});
我正在使用jquery treeview插件。有没有办法在jquery treeview pugin中处理? – Prasad 2010-01-05 14:20:25
看起来并不像开箱即可。你可以修改插件来做你需要的或者自己写的。 – PetersenDidIt 2010-01-05 14:48:56
这里的解决方案的荣誉:-),正是我们正在寻找的! – VarunC 2014-07-24 11:25:14