0

我正在使用Bootstrap選項卡並應用jQuery Sortable的拖動效果。到目前爲止,它在第一級工作正常,包括Bootstrap選項卡。但是,當它進入嵌套級別3級時,拖動效果無法正常工作。jQuery Sortable不適用於嵌套鏈接

也是第二級和第三級的Bootstrap Tab視圖,它的每個鏈接都沒有加載相應的div視圖(帶有.tab-pane和reference id的視圖),但第一級工作正常。我創建了每個鏈接的點擊功能,以刪除父活動的類,它顯示點擊鏈接視圖div,但似乎沒有任何工作。

var nestedList = $("ul.nested_with_switch li ul").children("li"); 

nestedList.click(function(){ 
    $(this).data('clicked', true); 
}) 

nestedList.click(function(){ 
    if($(this).data('clicked') === true){ 
    nestedList.parents("ul li").removeClass("active"); 
    nestedList.find("li").removeClass("active"); 
    } 
}) 

這是Code

+0

你似乎正在爲每個'nestedList'項目添加兩個點擊監聽器......這可能不是你想要的? –

+0

是的,我想我搞砸了代碼。 –

回答

0

開始刪除似乎是代碼,什麼也不做......取代:

nestedList.click(function(){ 
    $(this).data('clicked', true); 
}) 

nestedList.click(function(){ 
    if($(this).data('clicked') === true){ 
    nestedList.parents("ul li").removeClass("active"); 
    nestedList.find("li").removeClass("active"); 
    } 
}) 

有:

nestedList.click(function(){ 
    nestedList.parents("li").removeClass("active"); 
    nestedList.find("li").removeClass("active"); 
}) 

接下來,你可能想使用.children("li")代替.find("li"),但我我不是100%確定你要用你的代碼來完成什麼。

+0

感謝您的評論@Hamza。拖動僅在檢查開關時生效。當其爲真時,每個鏈接上的句柄將啓用每個鏈接的拖動效果。一級和二級工作正常,我關心的是第三級。 此外,Bootstrap Tab在嵌套鏈接的第一級工作正常,每次點擊子鏈接時都不會顯示相應的視圖。 –