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在嵌套链接的第一级工作正常,每次点击子链接时都不会显示相应的视图。 –