避免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