jquery - 在初始阶段折叠 TreeView

标签 jquery css

i am trying to collapse tree view but unable to do that please help me you can view demo from below link i want tree view to be collapse each node initially as per retirement it should expand particular node.

演示

http://www.jqueryscript.net/demo/Animated-Tree-View-Plugin-For-jQuery-Bootstrap-3-MultiNestedLists/

// Select the main list and add the class "hasSubmenu" in each LI that contains an UL
$('ul').each(function(){
  $this = $(this);
  $this.find("li").has("ul").addClass("hasSubmenu");
  $this.find("li").has("ul").css('collapsed', 'true');
});
// Find the last li in each level
$('li:last-child').each(function(){
  $this = $(this);
  // Check if LI has children
  if ($this.children('ul').length === 0){
    // Add border-left in every UL where the last LI has not children
    $this.closest('ul').css("border-left", "1px solid gray");
  } else {
    // Add border in child LI, except in the last one
    $this.closest('ul').children("li").not(":last").css("border-left","1px solid gray");
    // Add the class "addBorderBefore" to create the pseudo-element :defore in the last li
    $this.closest('ul').children("li").last().children("a").addClass("addBorderBefore");
    // Add margin in the first level of the list
    $this.closest('ul').css("margin-top","20px");
    // Add margin in other levels of the list
    $this.closest('ul').find("li").children("ul").css("margin-top","20px");
  };
});
// Add bold in li and levels above
$('ul li').each(function(){
  $this = $(this);
  $this.mouseenter(function(){
    $( this ).children("a").css({"font-weight":"bold","color":"#336b9b"});
  });
  $this.mouseleave(function(){
    $( this ).children("a").css({"font-weight":"normal","color":"#428bca"});
  });
});
// Add button to expand and condense - Using FontAwesome
$('ul li.hasSubmenu').each(function(){
  $this = $(this);
  $this.prepend("<a href='#'><i class='fa fa-minus-circle'></i><i style='display:none;' class='fa fa-plus-circle'></i></a>");
  $this.children("a").not(":last").removeClass().addClass("toogle");
});
// Actions to expand and consense
$('ul li.hasSubmenu a.toogle').click(function(){
  $this = $(this);
  $this.closest("li").children("ul").toggle("slow");
  $this.children("i").toggle();
  return false;
});

最佳答案

您可以尝试使用代码。会帮你的。 谢谢

$(document).read(function(){
   $('li.hasSubmenu ul').each(function(){
      $(this).hide();
   });
});

关于jquery - 在初始阶段折叠 TreeView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41039368/

相关文章:

PHP 和 HTML - 在用户登录时隐藏 <form>

html - 在 IE 中如何设置表格中的单元格高度以填充窗口?

JavaScript 错误 - 未捕获的语法错误 : Unexpected number

javascript - Jquery忽略具有 "disabled"类的元素

jquery - 根据下拉菜单显示/隐藏表单

javascript - 自动完成建议输入框填充条形码扫描仪

html - 当悬停在我的按钮上时,想要一个交易效果(按钮开始从左到右填充渐变颜色),

jQuery - 具有悬停效果的多个元素

jquery - 从右向左滑动切换 DIV

javascript - 如何让页面内容始终出现在导航栏下方?