Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 在删除JQuery Accordion时查找容器长度?_Jquery Ui_Jquery Ui Accordion - Fatal编程技术网

Jquery ui 在删除JQuery Accordion时查找容器长度?

Jquery ui 在删除JQuery Accordion时查找容器长度?,jquery-ui,jquery-ui-accordion,Jquery Ui,Jquery Ui Accordion,我有以下代码来删除动态生成的ui手风琴。当删除发生时(有效),我需要确定作为div的accordion容器是否为空。因此,如果用户删除手风琴,容器div现在为空,我需要调整包含div的大小(div是ui.layout窗格,当容器为空时,我需要为用户自动调整其大小) 当我删除accorion时,长度仍然是1。当它为0时,我需要调整大小。这可能吗 $( ".delete_accordion" ) .click(function() { var parent =

我有以下代码来删除动态生成的ui手风琴。当删除发生时(有效),我需要确定作为div的accordion容器是否为空。因此,如果用户删除手风琴,容器div现在为空,我需要调整包含div的大小(div是ui.layout窗格,当容器为空时,我需要为用户自动调整其大小)

当我删除accorion时,长度仍然是1。当它为0时,我需要调整大小。这可能吗

$( ".delete_accordion" )
        .click(function() {
            var parent = $(this).closest('h3');
            var head = parent.next('div');
            parent.add(head).fadeOut('slow',function(){$(this).remove();});    

            //length always returns 1 in the function even though it has been removed above.
            //perhaps there is an event or method I can intercept on delete?

            var parentHasClass = parent.hasClass("accordion");   

            var isempty = ($("#accordion").length == 0);
            alert(isempty);

            if(parentHasClass == "true"){                   
                if( isempty ){
                 myLayout.sizePane("west", 100);
                }                
            }

        });
直到淡出完成后才会调用
$(this).remove()
,因此从技术上讲,长度仍然是===1

您可以通过将其余的删除逻辑放入淡出回调来修复此问题:

  $( ".delete_accordion" )
          .click(function() {
              var parent = $(this).closest('h3');
              var head = parent.next('div');
              parent.add(head).fadeOut('slow',function(){
                $(this).remove();
                var parentHasClass = parent.hasClass("accordion");   

                var isempty = ($("#accordion").length == 0);
                alert(isempty);

                if(parentHasClass == "true"){                   
                    if( isempty ){
                     myLayout.sizePane("west", 100);
                    }                
                }
                });    

          });   

//I modified the selector as follows and now works great! Thanks Skylar!
$( ".delete_accordion" )
          .click(function() {
              var parent = $(this).closest('h3');
              var head = parent.next('div');
              parent.add(head).fadeOut('slow',function(){
                $(this).remove();
                var parentHasClass = parent.hasClass("accordion");  
                var isempty = ($("#accordion h3").length);
                if(isempty == 0 || parentHasClass == "true"){  
                     //alert(isempty);                 
                     myLayout.sizePane("west", 100);
                }
                });   

        });     

谢谢它仍然返回1,但我修改了选择器以查找组成手风琴的h3标记。选择器随后返回0。最终代码如附件所示。谢谢斯凯拉!