0

我发现了 jquery 的一个很奇怪的行为。我在这里有两个列表,我将 li 元素从一个拖放到另一个,当前排序由 ajax-mysql 保存。现在今天下午我注意到有时,只是有时最后一个丢弃项目的位置没有正确保存,当它应该是 4 或 5 时它被保存为“0”。我花了几个小时才发现这种行为在与警报直接相关,在物品掉落后触发:

alert(data);       <---- data is the current sorting of the ids

如果我删除此行,则会出现上述脚本的奇怪行为。也许有人以前经历过这样的事情并可以分享一些建议?

问候,马舍克

编辑:这是包含警报的功能:

            $(function() {

             $("#sortable2").sortable({

                  items: \'li:not(.col_header)\',
            connectWith: \'#sortable2, #sortable1, #sortable1b, #sortable1c\',   
            helper: \'clone\',
            placeholder: \'empfaenger-highlight\',
         revert: \'invalid\',
         update: function() {

              var data = $(this).sortable("serialize") + \'&user='.$user.'\';

              alert(data);
              var order = $(this).sortable("serialize") + 
              \'&action=updateList&user='.$user.'\'; 
             $.post("index.php?eID=moveitems", order, 
             function(theResponse){

                   $("#response").html(theResponse);
                   $("#response").slideDown(\'slow\');
                   slideout(); 

                 }); 

               } 

          }).disableSelection();

我尝试使用回调,以确保变量被完全加载:

                    $(function() {

                     $("#sortable2").sortable({

                          items: \'li:not(.col_header)\',
                          connectWith: \'#sortable2, #sortable1, #sortable1b, #sortable1c\',            
                          helper: \'clone\',
                          placeholder: \'empfaenger-highlight\',
                          revert: \'invalid\',
                          update: function() {



                          var data = $(this).sortable("serialize");

                               function doSomething(data) {

                          };

                               //alert(data);
                               var order = data + \'&action=updateList&feuser='.$user.'\'; 

                               $.post("index.php?eID=moveitems", order,  function(theResponse){

                          }); 

                     }  

                }).disableSelection();

但是所描述的错误行为仍然发生。有人可以告诉我,如果使用这个额外的回调函数是正确的方法吗?或者我将如何处理这个,以确保正确可变?谢谢你的建议...

4

1 回答 1

0

你是对的,可能更容易从输出代码中读取。剧本:

 <script type="text/javascript">
           $(document).ready(
           function () {
                function slideout(){

                setTimeout(function(){

                     $("#sortable3 .provider, #sortable3 .empfaenger, #response").fadeOut("slow", function () {

               });

           }, 2000);}


           $(function() {

                $("#sortable2").sortable({

                     items: 'li:not(.col_header)',
                    connectWith: '#sortable2, #sortable1, #sortable1b, #sortable1c',            
                    helper: 'clone',
                    placeholder: 'empfaenger-highlight',
                    revert: 'invalid',
                    update: function() {

      var data = $(this).sortable("serialize") + '&feuser=14';

      alert(data);
      var order = $(this).sortable("serialize") + 
      '&action=updateList&feuser=14'; 
      $.post("index.php?eID=moveitems", order, 
      function(theResponse){

                               $("#response").html(theResponse);
                               $("#response").slideDown('slow');
                               slideout();  

                          }); 

                     }  

                }).disableSelection();
于 2010-02-11T00:31:13.447 回答