【问题标题】:jQuery Sortable not working on nested linkjQuery Sortable 不适用于嵌套链接
【发布时间】:2014-05-14 01:07:59
【问题描述】:

我正在使用引导选项卡并应用jQuery Sortable 的拖动效果。到目前为止,它在包括 Bootstrap 选项卡在内的第一级上运行良好。但是当它进入嵌套级别的第3级时,拖动效果无法正常工作。

还有第 2 层和第 3 层的 Bootstrap Tab 视图,它的每个链接都没有加载相应的 div 视图(带有 .tab-pane 和参考 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

【问题讨论】:

  • 您似乎为每个 nestedList 项目添加了两个点击侦听器...这可能不是您想要的?
  • 是的,我想我弄乱了代码。

标签: javascript jquery twitter-bootstrap jquery-ui-sortable drag


【解决方案1】:

从删除似乎什么都不做的代码开始...替换:

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% 确定您要使用代码完成什么。

【讨论】:

  • 感谢@Hamza 的评论。拖动只会在选中 Switch 时生效。当它为真时,每个链接上的手柄将启用每个链接的拖动效果。第一级和第二级工作正常,我担心的是第三级。此外,在第一级工作正常的 Bootstrap 选项卡,在嵌套链接上,每次单击子链接时都不会显示其相应的视图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-01
  • 1970-01-01
  • 2012-11-20
相关资源
最近更新 更多