简体   繁体   English

如何在jQuery中的面板中追加行?

[英]How to append row in panel in jQuery?

在此处输入图片说明
can you please tell me how to append row in panel which is collapsible row (can be expand),I am able to append but it s not expand. 能否请您告诉我如何在可折叠行的面板中追加行(可以扩展),我可以追加但不能扩展。

I am getting this error while doing this step. 执行此步骤时出现此错误。 First click icon on << it open the left panel .Then I click add button it generate a row as well as it generate submenu of firstLevel.Then press + button it expand .but when you click add button again it generate another row and submenu but it is not expandable while click on + button? 首先单击<< <<图标打开左面板。然后单击添加按钮将生成一行并生成firstLevel子菜单。然后按+按钮将其展开。但是再次单击添加按钮时将生成另一行和子菜单但是点击+按钮时无法展开?
http://jsfiddle.net/eHded/1549/ http://jsfiddle.net/eHded/1549/

function addInmenu(id){
 alert(id)   
     var menuid="menu_"+id;
    // var data = $('#menuId li').html();
 $('#menuId  li').append('<ul><li id=' + menuid + '><a>'+menuid+'</a></li></ul>');
     $('.tree li').each(function () {
        if ($(this).children('ul').length > 0) {
            $(this).addClass('parent');
        }
    });
$('.tree li.parent > a').on('click',function () {
    //alert('--')
        $(this).parent().toggleClass('active');
        $(this).parent().children('ul').slideToggle('fast');
    });

}

Here is your code working in jsfiddle 这是您在jsfiddle中工作的代码

function addInmenu(id){ 
   var menuid="menu_"+id;
   // var data = $('#menuId li').html();

   $('#menuId li:first ').append('<ul><li id=' + menuid + '><a>'+menuid+'</a></li> </ul>');
   $('.tree li').each(function () {
     if ($(this).children('ul').length > 0) {
        $(this).addClass('parent');
     }
   });
   $('.tree li.parent > a').unbind("click");
   $('.tree li.parent > a').on('click',function () {
   //alert('--')
    $(this).parent().toggleClass('active');
    $(this).parent().children('ul').slideToggle('fast');
   });
}


$('#add').click(function () {
  var listItems = $("#ultest").children();
  var id;
  if (typeof ($("#ultest li:last").attr('id')) == 'undefined') {
    //alert('undefint');
    id = "tc_1"
  } else {
    id = $("#ultest li:last").attr('id');
    var index = id.indexOf("_");
    var count = id.substring(index + 1, id.length)
    count = parseInt(count);


    id = id.substring(0, index) + "_" + parseInt(count + 1);
   // alert(id)
  }

  if ($('.tree li.parent').hasClass('active')){        
    $('.tree li.parent').toggleClass('active');
    $('.tree li.parent').children('ul').slideToggle('fast');
  }
  $('#ultest').append('<li id=' + id + '><a href="#" class="foo">' + id + '</a></li>');
    //$('#ultest').listview('refresh');
    addInmenu(id);
});

UPDATED: 更新:

here is updated fiddle for reference jsfiddle here 这里更新了提琴供参考jsfiddle这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM